forked from phoenix/litellm-mirror
fix(utils.py): support deepseek tool calling
Fixes https://github.com/BerriAI/litellm/issues/5081
This commit is contained in:
parent
2f402b1cdd
commit
ff386f6b60
2 changed files with 29 additions and 18 deletions
|
@ -4085,9 +4085,28 @@ async def test_acompletion_gemini():
|
||||||
def test_completion_deepseek():
|
def test_completion_deepseek():
|
||||||
litellm.set_verbose = True
|
litellm.set_verbose = True
|
||||||
model_name = "deepseek/deepseek-chat"
|
model_name = "deepseek/deepseek-chat"
|
||||||
messages = [{"role": "user", "content": "Hey, how's it going?"}]
|
tools = [
|
||||||
|
{
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": "get_weather",
|
||||||
|
"description": "Get weather of an location, the user shoud supply a location first",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"location": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The city and state, e.g. San Francisco, CA",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["location"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
messages = [{"role": "user", "content": "How's the weather in Hangzhou?"}]
|
||||||
try:
|
try:
|
||||||
response = completion(model=model_name, messages=messages)
|
response = completion(model=model_name, messages=messages, tools=tools)
|
||||||
# Add any assertions here to check the response
|
# Add any assertions here to check the response
|
||||||
print(response)
|
print(response)
|
||||||
except litellm.APIError as e:
|
except litellm.APIError as e:
|
||||||
|
|
|
@ -3536,22 +3536,11 @@ def get_optional_params(
|
||||||
)
|
)
|
||||||
_check_valid_arg(supported_params=supported_params)
|
_check_valid_arg(supported_params=supported_params)
|
||||||
|
|
||||||
if frequency_penalty is not None:
|
optional_params = litellm.OpenAIConfig().map_openai_params(
|
||||||
optional_params["frequency_penalty"] = frequency_penalty
|
non_default_params=non_default_params,
|
||||||
if max_tokens is not None:
|
optional_params=optional_params,
|
||||||
optional_params["max_tokens"] = max_tokens
|
model=model,
|
||||||
if presence_penalty is not None:
|
)
|
||||||
optional_params["presence_penalty"] = presence_penalty
|
|
||||||
if stop is not None:
|
|
||||||
optional_params["stop"] = stop
|
|
||||||
if stream is not None:
|
|
||||||
optional_params["stream"] = stream
|
|
||||||
if temperature is not None:
|
|
||||||
optional_params["temperature"] = temperature
|
|
||||||
if logprobs is not None:
|
|
||||||
optional_params["logprobs"] = logprobs
|
|
||||||
if top_logprobs is not None:
|
|
||||||
optional_params["top_logprobs"] = top_logprobs
|
|
||||||
elif custom_llm_provider == "openrouter":
|
elif custom_llm_provider == "openrouter":
|
||||||
supported_params = get_supported_openai_params(
|
supported_params = get_supported_openai_params(
|
||||||
model=model, custom_llm_provider=custom_llm_provider
|
model=model, custom_llm_provider=custom_llm_provider
|
||||||
|
@ -4141,12 +4130,15 @@ def get_supported_openai_params(
|
||||||
"frequency_penalty",
|
"frequency_penalty",
|
||||||
"max_tokens",
|
"max_tokens",
|
||||||
"presence_penalty",
|
"presence_penalty",
|
||||||
|
"response_format",
|
||||||
"stop",
|
"stop",
|
||||||
"stream",
|
"stream",
|
||||||
"temperature",
|
"temperature",
|
||||||
"top_p",
|
"top_p",
|
||||||
"logprobs",
|
"logprobs",
|
||||||
"top_logprobs",
|
"top_logprobs",
|
||||||
|
"tools",
|
||||||
|
"tool_choice",
|
||||||
]
|
]
|
||||||
elif custom_llm_provider == "cohere":
|
elif custom_llm_provider == "cohere":
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue