victor HF Staff commited on
Commit
82f775d
·
1 Parent(s): e77d876

Implemented chat completion streaming functionality in the Playground component.

Browse files
src/lib/components/Playground/Playground.svelte CHANGED
@@ -63,19 +63,14 @@
63
  try {
64
  const hf = new HfInference(hfToken);
65
 
66
- const stream = await hf.textGenerationStream({
67
  model: currentModel,
68
- inputs: messages.map(m => m.content).join('\n'),
69
- parameters: {
70
- max_new_tokens: maxTokens,
71
- temperature: temperature,
72
- return_full_text: false
73
- }
74
- });
75
-
76
- for await (const response of stream) {
77
- if (streamingMessage) {
78
- streamingMessage.content += response.token.text;
79
  messages = [...messages];
80
  }
81
  }
 
63
  try {
64
  const hf = new HfInference(hfToken);
65
 
66
+ for await (const chunk of hf.chatCompletionStream({
67
  model: currentModel,
68
+ messages: messages.map(({ role, content }) => ({ role, content })),
69
+ temperature: temperature,
70
+ max_tokens: maxTokens
71
+ })) {
72
+ if (streamingMessage && chunk.choices[0]?.delta?.content) {
73
+ streamingMessage.content += chunk.choices[0].delta.content;
 
 
 
 
 
74
  messages = [...messages];
75
  }
76
  }