Skip to content

Commit

Permalink
recall msg
Browse files Browse the repository at this point in the history
  • Loading branch information
jackalcooper committed Feb 18, 2025
1 parent 75e5d6d commit cf0c770
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/client/platforms/siliconflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,22 @@ export class SiliconflowApi implements LLMApi {
(text: string, runTools: ChatMessageTool[]) => {
// console.log("parseSSE", text, runTools);
const json = JSON.parse(text);
console.log("json", json);
const choices = json.choices as Array<{
finish_reason: string;
delta: {
content: string | null;
tool_calls: ChatMessageTool[];
reasoning_content: string | null;
};
}>;
if (choices[0].finish_reason === "risky") {
return {
isThinking: false,
content: "",
shouldRecall: true,
};
}
const tool_calls = choices[0]?.delta?.tool_calls;
if (tool_calls?.length > 0) {
const index = tool_calls[0]?.index;
Expand Down
4 changes: 4 additions & 0 deletions app/utils/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ export function streamWithThink(
) => {
isThinking: boolean;
content: string | undefined;
shouldRecall?: boolean | undefined;
},
processToolMessage: (
requestPayload: any,
Expand Down Expand Up @@ -583,6 +584,9 @@ export function streamWithThink(
}
try {
const chunk = parseSSE(text, runTools);
if (!!chunk.shouldRecall) {
responseText = "👀 让我们换个话题聊聊吧";
}
// Skip if content is empty
if (!chunk?.content || chunk.content.length === 0) {
return;
Expand Down

0 comments on commit cf0c770

Please sign in to comment.