mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
Litellm dev 01 01 2025 p3 (#7503)
* fix(utils.py): add new validate tool choice helper function Prevents https://github.com/BerriAI/litellm/issues/7483 * fix(main.py): add tool choice validation on .completion() prevents user error like - https://github.com/BerriAI/litellm/issues/7483 * fix(utils.py): fix return val of tool choice validation logic
This commit is contained in:
parent
f96f54a0f5
commit
45b93f2721
3 changed files with 51 additions and 0 deletions
|
@ -6058,6 +6058,34 @@ def validate_chat_completion_user_messages(messages: List[AllMessageValues]):
|
|||
return messages
|
||||
|
||||
|
||||
def validate_chat_completion_tool_choice(
|
||||
tool_choice: Optional[Union[dict, str]]
|
||||
) -> Optional[Union[dict, str]]:
|
||||
"""
|
||||
Confirm the tool choice is passed in the OpenAI format.
|
||||
|
||||
Prevents user errors like: https://github.com/BerriAI/litellm/issues/7483
|
||||
"""
|
||||
from litellm.types.llms.openai import (
|
||||
ChatCompletionToolChoiceObjectParam,
|
||||
ChatCompletionToolChoiceStringValues,
|
||||
)
|
||||
|
||||
if tool_choice is None:
|
||||
return tool_choice
|
||||
elif isinstance(tool_choice, str):
|
||||
return tool_choice
|
||||
elif isinstance(tool_choice, dict):
|
||||
if tool_choice.get("type") is None or tool_choice.get("function") is None:
|
||||
raise Exception(
|
||||
f"Invalid tool choice, tool_choice={tool_choice}. Please ensure tool_choice follows the OpenAI spec"
|
||||
)
|
||||
return tool_choice
|
||||
raise Exception(
|
||||
f"Invalid tool choice, tool_choice={tool_choice}. Got={type(tool_choice)}. Expecting str, or dict. Please ensure tool_choice follows the OpenAI tool_choice spec"
|
||||
)
|
||||
|
||||
|
||||
class ProviderConfigManager:
|
||||
@staticmethod
|
||||
def get_provider_chat_config( # noqa: PLR0915
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue