Skip to content

Commit

Permalink
Add more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Neet-Nestor committed May 15, 2024
1 parent 8c2933b commit a775fff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/client/webllm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class WebLLMApi implements LLMApi {
} catch (err) {
console.error("Error in streaming chatCompletion", err);
options.onError?.(err as Error);
return;
}
} else {
try {
Expand All @@ -84,6 +85,7 @@ export class WebLLMApi implements LLMApi {
} catch (err) {
console.error("Error in non-streaming chatCompletion", err);
options.onError?.(err as Error);
return;
}
}

Expand Down
15 changes: 14 additions & 1 deletion app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const useChatStore = createPersistStore(
* this param is just shit
**/
const { max_tokens, ...modelcfg } = modelConfig;
// System prompt has to be the first message
// The first message must be from system
if (toBeSummarizedMsgs[0]?.role === "system") {
// Merge system prompts
toBeSummarizedMsgs[0].content =
Expand All @@ -623,6 +623,19 @@ export const useChatStore = createPersistStore(
...toBeSummarizedMsgs,
];
}
// The last message must be from user
if (
toBeSummarizedMsgs[toBeSummarizedMsgs.length - 1].role === "system"
) {
toBeSummarizedMsgs = toBeSummarizedMsgs.concat([
createMessage({
role: "user",
content: "",
date: "",
}),
]);
}

console.log("summarizeSession", messages);
webllm.chat({
messages: toBeSummarizedMsgs,
Expand Down

0 comments on commit a775fff

Please sign in to comment.