K00B404 commited on
Commit
13698e1
·
verified ·
1 Parent(s): ea863e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -20,28 +20,29 @@ def respond(
20
  top_p,
21
  ):
22
  messages = [{"role": "system", "content": system_message}]
23
-
24
  for val in history:
25
  if val[0]:
26
  messages.append({"role": "user", "content": val[0]})
27
  if val[1]:
28
  messages.append({"role": "assistant", "content": val[1]})
29
-
30
  messages.append({"role": "user", "content": message})
31
 
32
  response = ""
33
-
34
- for message in client.chat_completion(
35
- messages,
36
- max_tokens=max_tokens,
37
- stream=True,
38
- temperature=temperature,
39
- top_p=top_p,
40
- ):
41
- token = message.choices[0].delta.content
42
-
43
- response += token
44
- yield response
 
 
 
45
 
46
 
47
  demo = gr.ChatInterface(
 
20
  top_p,
21
  ):
22
  messages = [{"role": "system", "content": system_message}]
 
23
  for val in history:
24
  if val[0]:
25
  messages.append({"role": "user", "content": val[0]})
26
  if val[1]:
27
  messages.append({"role": "assistant", "content": val[1]})
 
28
  messages.append({"role": "user", "content": message})
29
 
30
  response = ""
31
+ try:
32
+ response_stream = client.chat_completion(
33
+ messages,
34
+ max_tokens=max_tokens,
35
+ stream=True,
36
+ temperature=temperature,
37
+ top_p=top_p,
38
+ )
39
+ for message in response_stream:
40
+ token = message.choices[0].delta.content
41
+ response += token
42
+ yield response
43
+ except (json.JSONDecodeError, ValueError) as e:
44
+ print(f"Error decoding response: {e}")
45
+ yield "An error occurred while processing the request."
46
 
47
 
48
  demo = gr.ChatInterface(