eliebak HF staff commited on
Commit
0842abf
1 Parent(s): 825dd19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -19,16 +19,21 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
19
  messages.append({"role": "user", "content": message})
20
 
21
  response = ""
22
- for message in client.chat_completion(
23
  messages,
24
  max_tokens=max_tokens,
25
  stream=True,
26
  temperature=temperature,
27
  top_p=top_p,
28
  ):
29
- token = message.choices[0].delta.content
30
- response += token
31
- yield history + [(message, response)]
 
 
 
 
 
32
 
33
  def clear_session():
34
  return "", []
 
19
  messages.append({"role": "user", "content": message})
20
 
21
  response = ""
22
+ for chunk in client.chat_completion(
23
  messages,
24
  max_tokens=max_tokens,
25
  stream=True,
26
  temperature=temperature,
27
  top_p=top_p,
28
  ):
29
+ if chunk.choices[0].delta.content is not None:
30
+ token = chunk.choices[0].delta.content
31
+ response += token
32
+ yield history + [(message, response)]
33
+
34
+ # If the response is empty, yield a default message
35
+ if not response:
36
+ yield history + [(message, "I apologize, but I couldn't generate a response.")]
37
 
38
  def clear_session():
39
  return "", []