Update openai_api.py

解决调用api的bug:response, _ = model.chat_stream(tokenizer, query, history=history)
ValueError: too many values to unpack (expected 2)

用api的时候建议把stream改成false
main
Artificial 1 year ago committed by GitHub
parent 677180a653
commit d2fc7c95db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -123,10 +123,11 @@ async def create_chat_completion(request: ChatCompletionRequest):
generate = predict(query, history, request.model) generate = predict(query, history, request.model)
return EventSourceResponse(generate, media_type="text/event-stream") return EventSourceResponse(generate, media_type="text/event-stream")
response, _ = model.chat_stream(tokenizer, query, history=history) responses = [resp for resp in model.chat_stream(tokenizer, query, history=history)]
combined_response = ''.join(responses)
choice_data = ChatCompletionResponseChoice( choice_data = ChatCompletionResponseChoice(
index=0, index=0,
message=ChatMessage(role="assistant", content=response), message=ChatMessage(role="assistant", content=combined_response),
finish_reason="stop" finish_reason="stop"
) )

Loading…
Cancel
Save