update fastch_chat: disable streaming in swagger besides streaming in ApiRequest
This commit is contained in:
parent
d67e354276
commit
1a112c6908
|
|
@ -18,7 +18,7 @@ class OpenAiChatMsgIn(BaseModel):
|
|||
n: int = 1
|
||||
max_tokens: int = 1024
|
||||
stop: List[str] = []
|
||||
stream: bool = True
|
||||
stream: bool = False
|
||||
presence_penalty: int = 0
|
||||
frequency_penalty: int = 0
|
||||
|
||||
|
|
@ -31,10 +31,21 @@ async def openai_chat(msg: OpenAiChatMsgIn):
|
|||
print(msg)
|
||||
|
||||
async def get_response(msg):
|
||||
response = openai.ChatCompletion.create(**msg.dict())
|
||||
data = msg.dict()
|
||||
data["streaming"] = True
|
||||
data.pop("stream")
|
||||
response = openai.ChatCompletion.create(**data)
|
||||
|
||||
if msg.stream:
|
||||
for chunk in response.choices[0].message.content:
|
||||
print(chunk)
|
||||
yield chunk
|
||||
else:
|
||||
answer = ""
|
||||
for chunk in response.choices[0].message.content:
|
||||
answer += chunk
|
||||
print(answer)
|
||||
yield(answer)
|
||||
|
||||
return StreamingResponse(
|
||||
get_response(msg),
|
||||
|
|
|
|||
Loading…
Reference in New Issue