calycekr nsarrazin commited on
Commit
c5af266
·
unverified ·
1 Parent(s): 307c245

fix: Improve error handling in generateFromDefaultEndpoint (#1853)

Browse files

- 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>

src/lib/server/generateFromDefaultEndpoint.ts CHANGED
@@ -11,11 +11,10 @@ export async function* generateFromDefaultEndpoint({
11
  preprompt?: string;
12
  generateSettings?: Record<string, unknown>;
13
  }): AsyncGenerator<MessageUpdate, string, undefined> {
14
- const endpoint = await taskModel.getEndpoint();
15
-
16
- const tokenStream = await endpoint({ messages, preprompt, generateSettings });
17
-
18
  try {
 
 
 
19
  for await (const output of tokenStream) {
20
  // if not generated_text is here it means the generation is not done
21
  if (output.generated_text) {
 
11
  preprompt?: string;
12
  generateSettings?: Record<string, unknown>;
13
  }): AsyncGenerator<MessageUpdate, string, undefined> {
 
 
 
 
14
  try {
15
+ const endpoint = await taskModel.getEndpoint();
16
+ const tokenStream = await endpoint({ messages, preprompt, generateSettings });
17
+
18
  for await (const output of tokenStream) {
19
  // if not generated_text is here it means the generation is not done
20
  if (output.generated_text) {