zhangtao commited on
Commit
5b3edb5
1 Parent(s): 650d572

修改返回值

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -31,14 +31,12 @@ def chat_stream_completion(messages, history, system_prompt):
31
  messages=messages_prompts,
32
  stream=True
33
  )
34
- partial_message = []
35
  for chunk in response:
36
- print(json.dumps(chunk, ensure_ascii=False, indent=2))
37
- partial_message.append(chunk)
38
- # if len(chunk['choices'][0]) != 0:
39
- # partial_message = partial_message + \
40
- # chunk['choices'][0]['content']
41
- yield json.dumps(partial_message, ensure_ascii=False, indent=2)
42
 
43
 
44
  gr.ChatInterface(chat_stream_completion,
 
31
  messages=messages_prompts,
32
  stream=True
33
  )
34
+ partial_message = ""
35
  for chunk in response:
36
+ if len(chunk['choices'][0]["delta"]) != 0 and "content" in chunk['choices'][0]["delta"]:
37
+ partial_message = partial_message + \
38
+ chunk['choices'][0]["delta"]["content"]
39
+ yield partial_message
 
 
40
 
41
 
42
  gr.ChatInterface(chat_stream_completion,