fix: combine message correctly (#7038)

This commit is contained in:
darkskygit
2024-05-23 06:16:31 +00:00
parent 3eaddd6e42
commit f8fee55b3d
3 changed files with 10 additions and 22 deletions

View File

@@ -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}`;

View File

@@ -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,
};
}

View File

@@ -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 : [],
};
});