Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: combine message correctly (#7038)

darkskygitf8fee55b3d39
diff --git a/packages/backend/server/src/plugins/copilot/prompt.ts b/packages/backend/server/src/plugins/copilot/prompt.ts
index 32da83384c..a513b0ae9b 100644
--- a/packages/backend/server/src/plugins/copilot/prompt.ts
+++ b/packages/backend/server/src/plugins/copilot/prompt.ts
@@ -25,6 +25,8 @@ function extractMustacheParams(template: string) {
return Array.from(new Set(params));
}
+const EXCLUDE_MISSING_WARN_PARAMS = ['lora'];
+
export class ChatPrompt {
private readonly logger = new Logger(ChatPrompt.name);
public readonly encoder: Tokenizer | null;
@@ -97,7 +99,7 @@ export class ChatPrompt {
typeof income !== 'string' ||
(Array.isArray(options) && !options.includes(income))
) {
- if (sessionId) {
+ if (sessionId && !EXCLUDE_MISSING_WARN_PARAMS.includes(key)) {
const prefix = income
? `Invalid param value: ${key}=${income}`
: `Missing param value: ${key}`;
diff --git a/packages/backend/server/src/plugins/copilot/providers/fal.ts b/packages/backend/server/src/plugins/copilot/providers/fal.ts
index 69d3d8fd0f..5f9c690036 100644
--- a/packages/backend/server/src/plugins/copilot/providers/fal.ts
+++ b/packages/backend/server/src/plugins/copilot/providers/fal.ts
@@ -89,7 +89,7 @@ export class FalProvider
).filter(v => typeof v === 'string' && v.length);
return {
image_url: attachments?.[0],
- prompt: content || undefined,
+ prompt: content,
lora: lora.length ? lora : undefined,
};
}
diff --git a/packages/backend/server/src/plugins/copilot/session.ts b/packages/backend/server/src/plugins/copilot/session.ts
index 6dd898d446..6df6b255c1 100644
--- a/packages/backend/server/src/plugins/copilot/session.ts
+++ b/packages/backend/server/src/plugins/copilot/session.ts
@@ -7,7 +7,7 @@ import { FeatureManagementService } from '../../core/features';
import { QuotaService } from '../../core/quota';
import { PaymentRequiredException } from '../../fundamentals';
import { ChatMessageCache } from './message';
-import { ChatPrompt, PromptService } from './prompt';
+import { PromptService } from './prompt';
import {
AvailableModel,
ChatHistory,
@@ -129,7 +129,7 @@ export class ChatSession implements AsyncDisposable {
// we should combine it with the user message in the prompt
if (
messages.length === 1 &&
- firstMessage?.content &&
+ firstMessage &&
this.state.prompt.paramKeys.includes('content')
) {
const normalizedParams = {
@@ -258,27 +258,13 @@ export class ChatSessionService {
createdAt: 'asc',
},
},
- prompt: {
- select: {
- name: true,
- action: true,
- model: true,
- messages: {
- select: {
- role: true,
- content: true,
- createdAt: true,
- },
- orderBy: {
- idx: 'asc',
- },
- },
- },
- },
+ promptName: true,
},
})
.then(async session => {
if (!session) return;
+ const prompt = await this.prompt.get(session.promptName);
+ if (!prompt) throw new Error(`Prompt not found: ${session.promptName}`);
const messages = ChatMessageSchema.array().safeParse(session.messages);
@@ -287,7 +273,7 @@ export class ChatSessionService {
userId: session.userId,
workspaceId: session.workspaceId,
docId: session.docId,
- prompt: ChatPrompt.createFromPrompt(session.prompt),
+ prompt,
messages: messages.success ? messages.data : [],
};
});