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
|
n: int = 1
|
||||||
max_tokens: int = 1024
|
max_tokens: int = 1024
|
||||||
stop: List[str] = []
|
stop: List[str] = []
|
||||||
stream: bool = True
|
stream: bool = False
|
||||||
presence_penalty: int = 0
|
presence_penalty: int = 0
|
||||||
frequency_penalty: int = 0
|
frequency_penalty: int = 0
|
||||||
|
|
||||||
|
|
@ -31,10 +31,21 @@ async def openai_chat(msg: OpenAiChatMsgIn):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
async def get_response(msg):
|
async def get_response(msg):
|
||||||
response = openai.ChatCompletion.create(**msg.dict())
|
data = msg.dict()
|
||||||
for chunk in response.choices[0].message.content:
|
data["streaming"] = True
|
||||||
print(chunk)
|
data.pop("stream")
|
||||||
yield chunk
|
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(
|
return StreamingResponse(
|
||||||
get_response(msg),
|
get_response(msg),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue