forked from phoenix/litellm-mirror
fix(utils.py): fix mistral api tool calling response
This commit is contained in:
parent
4acdde988f
commit
ab24f61099
3 changed files with 20 additions and 0 deletions
|
@ -650,6 +650,7 @@
|
||||||
"input_cost_per_token": 0.000002,
|
"input_cost_per_token": 0.000002,
|
||||||
"output_cost_per_token": 0.000006,
|
"output_cost_per_token": 0.000006,
|
||||||
"litellm_provider": "mistral",
|
"litellm_provider": "mistral",
|
||||||
|
"supports_function_calling": true,
|
||||||
"mode": "chat"
|
"mode": "chat"
|
||||||
},
|
},
|
||||||
"mistral/mistral-small-latest": {
|
"mistral/mistral-small-latest": {
|
||||||
|
@ -659,6 +660,7 @@
|
||||||
"input_cost_per_token": 0.000002,
|
"input_cost_per_token": 0.000002,
|
||||||
"output_cost_per_token": 0.000006,
|
"output_cost_per_token": 0.000006,
|
||||||
"litellm_provider": "mistral",
|
"litellm_provider": "mistral",
|
||||||
|
"supports_function_calling": true,
|
||||||
"mode": "chat"
|
"mode": "chat"
|
||||||
},
|
},
|
||||||
"mistral/mistral-medium": {
|
"mistral/mistral-medium": {
|
||||||
|
|
|
@ -10000,6 +10000,22 @@ class CustomStreamWrapper:
|
||||||
t.function.arguments = ""
|
t.function.arguments = ""
|
||||||
_json_delta = delta.model_dump()
|
_json_delta = delta.model_dump()
|
||||||
print_verbose(f"_json_delta: {_json_delta}")
|
print_verbose(f"_json_delta: {_json_delta}")
|
||||||
|
if "role" not in _json_delta or _json_delta["role"] is None:
|
||||||
|
_json_delta["role"] = (
|
||||||
|
"assistant" # mistral's api returns role as None
|
||||||
|
)
|
||||||
|
if "tool_calls" in _json_delta and isinstance(
|
||||||
|
_json_delta["tool_calls"], list
|
||||||
|
):
|
||||||
|
for tool in _json_delta["tool_calls"]:
|
||||||
|
if (
|
||||||
|
isinstance(tool, dict)
|
||||||
|
and "function" in tool
|
||||||
|
and isinstance(tool["function"], dict)
|
||||||
|
and ("type" not in tool or tool["type"] is None)
|
||||||
|
):
|
||||||
|
# if function returned but type set to None - mistral's api returns type: None
|
||||||
|
tool["type"] = "function"
|
||||||
model_response.choices[0].delta = Delta(**_json_delta)
|
model_response.choices[0].delta = Delta(**_json_delta)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -650,6 +650,7 @@
|
||||||
"input_cost_per_token": 0.000002,
|
"input_cost_per_token": 0.000002,
|
||||||
"output_cost_per_token": 0.000006,
|
"output_cost_per_token": 0.000006,
|
||||||
"litellm_provider": "mistral",
|
"litellm_provider": "mistral",
|
||||||
|
"supports_function_calling": true,
|
||||||
"mode": "chat"
|
"mode": "chat"
|
||||||
},
|
},
|
||||||
"mistral/mistral-small-latest": {
|
"mistral/mistral-small-latest": {
|
||||||
|
@ -659,6 +660,7 @@
|
||||||
"input_cost_per_token": 0.000002,
|
"input_cost_per_token": 0.000002,
|
||||||
"output_cost_per_token": 0.000006,
|
"output_cost_per_token": 0.000006,
|
||||||
"litellm_provider": "mistral",
|
"litellm_provider": "mistral",
|
||||||
|
"supports_function_calling": true,
|
||||||
"mode": "chat"
|
"mode": "chat"
|
||||||
},
|
},
|
||||||
"mistral/mistral-medium": {
|
"mistral/mistral-medium": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue