### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)tags/v0.6.0
| resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") | resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8") | ||||
| return resp | return resp | ||||
| else: | else: | ||||
| ans = chat(dia, msg, False, **req) | |||||
| ans = chat(dia, msg, **req) | |||||
| fillin_conv(ans) | fillin_conv(ans) | ||||
| API4ConversationService.append_message(conv.id, conv.to_dict()) | API4ConversationService.append_message(conv.id, conv.to_dict()) | ||||
| return get_json_result(data=ans) | return get_json_result(data=ans) |
| return resp | return resp | ||||
| else: | else: | ||||
| ans = chat(dia, msg, False, **req) | |||||
| ans = chat(dia, msg, **req) | |||||
| fillin_conv(ans) | fillin_conv(ans) | ||||
| ConversationService.update_by_id(conv.id, conv.to_dict()) | ConversationService.update_by_id(conv.id, conv.to_dict()) | ||||
| return get_json_result(data=ans) | return get_json_result(data=ans) |
| if not resp.choices[0].delta.content:continue | if not resp.choices[0].delta.content:continue | ||||
| delta = resp.choices[0].delta.content | delta = resp.choices[0].delta.content | ||||
| ans += delta | ans += delta | ||||
| tk_count = resp.usage.total_tokens if response.usage else 0 | |||||
| if resp.output.choices[0].finish_reason == "length": | |||||
| if resp.choices[0].finish_reason == "length": | |||||
| ans += "...\nFor the content length reason, it stopped, continue?" if is_english( | ans += "...\nFor the content length reason, it stopped, continue?" if is_english( | ||||
| [ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?" | [ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?" | ||||
| tk_count = resp.usage.total_tokens | |||||
| if resp.choices[0].finish_reason == "stop": tk_count = resp.usage.total_tokens | |||||
| yield ans | yield ans | ||||
| except Exception as e: | except Exception as e: | ||||
| yield ans + "\n**ERROR**: " + str(e) | yield ans + "\n**ERROR**: " + str(e) |