refac
This commit is contained in:
1 parent
7d77efe0f1
commit
ba556bd8f0
3 files changed
+34
-21
No files matched your search
@@ -66,6 +66,8 @@ USAGE_COST_KEYS = {
|
||||
'completion_cost',
|
||||
}
|
||||
|
||||
USAGE_SUMMABLE_KEYS = USAGE_TOKEN_KEYS | USAGE_COST_KEYS
|
||||
|
||||
USAGE_DETAIL_KEYS = {
|
||||
'prompt_tokens_details',
|
||||
'completion_tokens_details',
|
||||
@@ -115,7 +117,7 @@ def merge_usage(current: dict | None, incoming: dict | None) -> dict:
|
||||
|
||||
result = {**current_usage, **incoming_usage}
|
||||
|
||||
for key in USAGE_TOKEN_KEYS | USAGE_COST_KEYS:
|
||||
for key in USAGE_SUMMABLE_KEYS:
|
||||
if key in current_usage or key in incoming_usage:
|
||||
current_value = current_usage.get(key, 0)
|
||||
incoming_value = incoming_usage.get(key, 0)
|
||||
@@ -238,9 +240,10 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
|
||||
data = json.loads(data)
|
||||
|
||||
model = data.get('model', 'ollama')
|
||||
message_content = data.get('message', {}).get('content', None)
|
||||
reasoning_content = data.get('message', {}).get('thinking', None)
|
||||
tool_calls = data.get('message', {}).get('tool_calls', None)
|
||||
message = data.get('message') or {}
|
||||
message_content = message.get('content', None)
|
||||
reasoning_content = message.get('thinking', None)
|
||||
tool_calls = message.get('tool_calls', None)
|
||||
openai_tool_calls = None
|
||||
|
||||
if tool_calls:
|
||||
@@ -253,8 +256,9 @@ async def convert_streaming_response_ollama_to_openai(ollama_streaming_response)
|
||||
if done:
|
||||
usage = convert_ollama_usage_to_openai(data)
|
||||
|
||||
data = openai_chat_chunk_message_template(model, message_content, reasoning_content, openai_tool_calls, usage)
|
||||
data['id'] = completion_id
|
||||
data = openai_chat_chunk_message_template(
|
||||
model, message_content, reasoning_content, openai_tool_calls, usage, message_id=completion_id
|
||||
)
|
||||
|
||||
# First chunk must carry delta.role (OpenAI spec).
|
||||
if first:
|
||||
|
||||
Reference in new issue
Block a user