refac
This commit is contained in:
1 parent
3c8d658160
commit
0b867590a8
1 file changed
+3
-1
@@ -144,6 +144,7 @@ def convert_response_ollama_to_openai(ollama_response: dict) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
async def convert_streaming_response_ollama_to_openai(ollama_streaming_response):
|
async def convert_streaming_response_ollama_to_openai(ollama_streaming_response):
|
||||||
|
has_tool_calls = False
|
||||||
async for data in ollama_streaming_response.body_iterator:
|
async for data in ollama_streaming_response.body_iterator:
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
|
|
||||||
@@ -155,6 +156,7 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
|
|||||||
|
|
||||||
if tool_calls:
|
if tool_calls:
|
||||||
openai_tool_calls = convert_ollama_tool_call_to_openai(tool_calls)
|
openai_tool_calls = convert_ollama_tool_call_to_openai(tool_calls)
|
||||||
|
has_tool_calls = True
|
||||||
|
|
||||||
done = data.get("done", False)
|
done = data.get("done", False)
|
||||||
|
|
||||||
@@ -166,7 +168,7 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
|
|||||||
model, message_content, reasoning_content, openai_tool_calls, usage
|
model, message_content, reasoning_content, openai_tool_calls, usage
|
||||||
)
|
)
|
||||||
|
|
||||||
if done and openai_tool_calls:
|
if done and has_tool_calls:
|
||||||
data["choices"][0]["finish_reason"] = "tool_calls"
|
data["choices"][0]["finish_reason"] = "tool_calls"
|
||||||
|
|
||||||
line = f"data: {json.dumps(data)}\n\n"
|
line = f"data: {json.dumps(data)}\n\n"
|
||||||
|
|||||||
Reference in new issue
Block a user