mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix: combine message correctly (#7038)
This commit is contained in:
@@ -25,6 +25,8 @@ function extractMustacheParams(template: string) {
|
|||||||
return Array.from(new Set(params));
|
return Array.from(new Set(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EXCLUDE_MISSING_WARN_PARAMS = ['lora'];
|
||||||
|
|
||||||
export class ChatPrompt {
|
export class ChatPrompt {
|
||||||
private readonly logger = new Logger(ChatPrompt.name);
|
private readonly logger = new Logger(ChatPrompt.name);
|
||||||
public readonly encoder: Tokenizer | null;
|
public readonly encoder: Tokenizer | null;
|
||||||
@@ -97,7 +99,7 @@ export class ChatPrompt {
|
|||||||
typeof income !== 'string' ||
|
typeof income !== 'string' ||
|
||||||
(Array.isArray(options) && !options.includes(income))
|
(Array.isArray(options) && !options.includes(income))
|
||||||
) {
|
) {
|
||||||
if (sessionId) {
|
if (sessionId && !EXCLUDE_MISSING_WARN_PARAMS.includes(key)) {
|
||||||
const prefix = income
|
const prefix = income
|
||||||
? `Invalid param value: ${key}=${income}`
|
? `Invalid param value: ${key}=${income}`
|
||||||
: `Missing param value: ${key}`;
|
: `Missing param value: ${key}`;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export class FalProvider
|
|||||||
).filter(v => typeof v === 'string' && v.length);
|
).filter(v => typeof v === 'string' && v.length);
|
||||||
return {
|
return {
|
||||||
image_url: attachments?.[0],
|
image_url: attachments?.[0],
|
||||||
prompt: content || undefined,
|
prompt: content,
|
||||||
lora: lora.length ? lora : undefined,
|
lora: lora.length ? lora : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { FeatureManagementService } from '../../core/features';
|
|||||||
import { QuotaService } from '../../core/quota';
|
import { QuotaService } from '../../core/quota';
|
||||||
import { PaymentRequiredException } from '../../fundamentals';
|
import { PaymentRequiredException } from '../../fundamentals';
|
||||||
import { ChatMessageCache } from './message';
|
import { ChatMessageCache } from './message';
|
||||||
import { ChatPrompt, PromptService } from './prompt';
|
import { PromptService } from './prompt';
|
||||||
import {
|
import {
|
||||||
AvailableModel,
|
AvailableModel,
|
||||||
ChatHistory,
|
ChatHistory,
|
||||||
@@ -129,7 +129,7 @@ export class ChatSession implements AsyncDisposable {
|
|||||||
// we should combine it with the user message in the prompt
|
// we should combine it with the user message in the prompt
|
||||||
if (
|
if (
|
||||||
messages.length === 1 &&
|
messages.length === 1 &&
|
||||||
firstMessage?.content &&
|
firstMessage &&
|
||||||
this.state.prompt.paramKeys.includes('content')
|
this.state.prompt.paramKeys.includes('content')
|
||||||
) {
|
) {
|
||||||
const normalizedParams = {
|
const normalizedParams = {
|
||||||
@@ -258,27 +258,13 @@ export class ChatSessionService {
|
|||||||
createdAt: 'asc',
|
createdAt: 'asc',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
prompt: {
|
promptName: true,
|
||||||
select: {
|
|
||||||
name: true,
|
|
||||||
action: true,
|
|
||||||
model: true,
|
|
||||||
messages: {
|
|
||||||
select: {
|
|
||||||
role: true,
|
|
||||||
content: true,
|
|
||||||
createdAt: true,
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
idx: 'asc',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async session => {
|
.then(async session => {
|
||||||
if (!session) return;
|
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);
|
const messages = ChatMessageSchema.array().safeParse(session.messages);
|
||||||
|
|
||||||
@@ -287,7 +273,7 @@ export class ChatSessionService {
|
|||||||
userId: session.userId,
|
userId: session.userId,
|
||||||
workspaceId: session.workspaceId,
|
workspaceId: session.workspaceId,
|
||||||
docId: session.docId,
|
docId: session.docId,
|
||||||
prompt: ChatPrompt.createFromPrompt(session.prompt),
|
prompt,
|
||||||
messages: messages.success ? messages.data : [],
|
messages: messages.success ? messages.data : [],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user