feat: append try catch (#280)

This commit is contained in:
Lan
2025-06-12 20:43:50 +08:00
committed by GitHub
parent 4c2fe2e7f5
commit 7d38e5f900

View File

@@ -40,9 +40,10 @@ export async function* chatStream(
env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY || env.NEXT_PUBLIC_STATIC_WEBSITE_ONLY ||
location.search.includes("mock") || location.search.includes("mock") ||
location.search.includes("replay=") location.search.includes("replay=")
) { )
return yield* chatReplayStream(userMessage, params, options); return yield* chatReplayStream(userMessage, params, options);
}
try{
const stream = fetchStream(resolveServiceURL("chat/stream"), { const stream = fetchStream(resolveServiceURL("chat/stream"), {
body: JSON.stringify({ body: JSON.stringify({
messages: [{ role: "user", content: userMessage }], messages: [{ role: "user", content: userMessage }],
@@ -50,12 +51,16 @@ export async function* chatStream(
}), }),
signal: options.abortSignal, signal: options.abortSignal,
}); });
for await (const event of stream) { for await (const event of stream) {
yield { yield {
type: event.event, type: event.event,
data: JSON.parse(event.data), data: JSON.parse(event.data),
} as ChatEvent; } as ChatEvent;
} }
}catch(e){
console.error(e);
}
} }
async function* chatReplayStream( async function* chatReplayStream(