feat: pass the provider's finish reason to outlet filters (#32079)

Outlet filters see the finished reply with its content and token usage, but had no way to tell whether the model ended on its own, ran into the token limit or stopped to call a tool, short of reading every chunk in a stream filter. For OpenAI-compatible and Ollama models, the assistant message handed to outlet now carries finish_reason with the value the provider reported on the last model call of the turn, for streaming and non-streaming replies. Ollama replies cut off by the token limit now report length as well, where they always said stop before.
This commit is contained in:
Classic298 authored and GitHub committed 2026-10-08 19:36:47 +04:00
1 parent ce18eca340
commit 039867feba
2 files changed
+19

No files matched your search

+5
View File
@@ -224,6 +224,8 @@ def convert_response_ollama_to_openai(ollama_response: dict) -> dict:
response = openai_chat_completion_message_template(
model, message_content, reasoning_content, openai_tool_calls, usage
)
if not openai_tool_calls and ollama_response.get('done_reason'):
response['choices'][0]['finish_reason'] = ollama_response['done_reason']
return response
@@ -247,6 +249,7 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
has_tool_calls = True
done = data.get('done', False)
done_reason = data.get('done_reason')
usage = None
if done:
@@ -263,6 +266,8 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
if done and has_tool_calls:
data['choices'][0]['finish_reason'] = 'tool_calls'
elif done_reason:
data['choices'][0]['finish_reason'] = done_reason
line = f'data: {JSONCodec.dumps(data)}\n\n'
yield line