emeses commited on
Commit
4cf6bf3
·
1 Parent(s): a677db4

Update space

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -27,17 +27,20 @@ def respond(
27
 
28
  response = ""
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
 
 
 
41
 
42
 
43
  """
 
27
 
28
  response = ""
29
 
30
+ try:
31
+ for chunk in client.chat_completion(
32
+ messages,
33
+ max_tokens=max_tokens,
34
+ stream=True,
35
+ temperature=temperature,
36
+ top_p=top_p,
37
+ ):
38
+ # The API returns the text directly in streaming mode
39
+ if chunk:
40
+ response += chunk
41
+ yield response
42
+ except Exception as e:
43
+ yield f"Error: {str(e)}"
44
 
45
 
46
  """