This commit is contained in:
Samuel 2024-10-18 12:06:00 +00:00
parent cac27b2730
commit bedcb6cce8

View File

@ -566,16 +566,13 @@ async def handle_streaming_response(request: Request, response: Response,
async def handle_nonstreaming_response(request: Request, response: Response, async def handle_nonstreaming_response(request: Request, response: Response,
tools: dict, user: UserModel, data_items: list) -> JSONResponse: tools: dict, user: UserModel, data_items: list) -> JSONResponse:
# It only should be one response ince we are in the non streaming scenario # It only should be one response since we are in the non streaming scenario
async for data in response.body_iterator: async for data in response.body_iterator:
content = data content = data
citations = [] citations = []
response_dict = json.loads(content) response_dict = json.loads(content)
body = json.loads(request._body) body = json.loads(request._body)
content_type = response.headers["Content-Type"]
is_openai = "text/event-stream" in content_type
is_ollama = "application/x-ndjson" in content_type
while response_dict["choices"][0]["finish_reason"] == "tool_calls": while response_dict["choices"][0]["finish_reason"] == "tool_calls":
body["messages"].append(response_dict["choices"][0]["message"]) body["messages"].append(response_dict["choices"][0]["message"])