No need for double-try
Browse files
src/lib/components/InferencePlayground/inferencePlaygroundUtils.ts
CHANGED
@@ -20,26 +20,18 @@ export async function handleStreamingResponse(
|
|
20 |
...conversation.messages
|
21 |
];
|
22 |
let out = '';
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
)
|
33 |
-
|
34 |
-
|
35 |
-
onChunk(out);
|
36 |
-
}
|
37 |
-
}
|
38 |
-
} catch (error) {
|
39 |
-
if (error.name === 'AbortError') {
|
40 |
-
console.log('Stream aborted');
|
41 |
-
} else {
|
42 |
-
throw error;
|
43 |
}
|
44 |
}
|
45 |
}
|
|
|
20 |
...conversation.messages
|
21 |
];
|
22 |
let out = '';
|
23 |
+
for await (const chunk of hf.chatCompletionStream(
|
24 |
+
{
|
25 |
+
model: conversation.model.id,
|
26 |
+
messages,
|
27 |
+
temperature: conversation.config.temperature,
|
28 |
+
max_tokens: conversation.config.maxTokens
|
29 |
+
},
|
30 |
+
{ signal: abortController.signal }
|
31 |
+
)) {
|
32 |
+
if (chunk.choices && chunk.choices.length > 0 && chunk.choices[0]?.delta?.content) {
|
33 |
+
out += chunk.choices[0].delta.content;
|
34 |
+
onChunk(out);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
}
|
37 |
}
|