Skip to content

Commit b946371

Browse files
calycekrnsarrazin
andauthored
fix: Improve error handling in generateFromDefaultEndpoint (#1853)
- Refactor error handling in the generateFromDefaultEndpoint function to prevent the Node.js process from crashing when an AbortError occurs. - Wrapped the getEndpoint and endpoint calls within a try...catch block to ensure that exceptions are caught and the process remains stable. Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
1 parent 5880ea7 commit b946371

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/lib/server/generateFromDefaultEndpoint.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ export async function* generateFromDefaultEndpoint({
1111
preprompt?: string;
1212
generateSettings?: Record<string, unknown>;
1313
}): AsyncGenerator<MessageUpdate, string, undefined> {
14-
const endpoint = await taskModel.getEndpoint();
15-
16-
const tokenStream = await endpoint({ messages, preprompt, generateSettings });
17-
1814
try {
15+
const endpoint = await taskModel.getEndpoint();
16+
const tokenStream = await endpoint({ messages, preprompt, generateSettings });
17+
1918
for await (const output of tokenStream) {
2019
// if not generated_text is here it means the generation is not done
2120
if (output.generated_text) {

0 commit comments

Comments
 (0)