forked from phoenix/litellm-mirror
(feat) completion: add response_format, seed, tools, tool_choice
This commit is contained in:
parent
3c03e82f98
commit
7abb65d53f
2 changed files with 19 additions and 2 deletions
|
@ -255,6 +255,11 @@ def completion(
|
||||||
frequency_penalty: Optional[float]=None,
|
frequency_penalty: Optional[float]=None,
|
||||||
logit_bias: dict = {},
|
logit_bias: dict = {},
|
||||||
user: str = "",
|
user: str = "",
|
||||||
|
# openai v1.0+ new params
|
||||||
|
response_format: Optional[dict] = None,
|
||||||
|
seed: Optional[int] = None,
|
||||||
|
tools: Optional[List] = None,
|
||||||
|
tool_choice: Optional[str] = None,
|
||||||
deployment_id = None,
|
deployment_id = None,
|
||||||
|
|
||||||
# set api_base, api_version, api_key
|
# set api_base, api_version, api_key
|
||||||
|
@ -329,7 +334,7 @@ def completion(
|
||||||
eos_token = kwargs.get("eos_token", None)
|
eos_token = kwargs.get("eos_token", None)
|
||||||
acompletion = kwargs.get("acompletion", False)
|
acompletion = kwargs.get("acompletion", False)
|
||||||
######## end of unpacking kwargs ###########
|
######## end of unpacking kwargs ###########
|
||||||
openai_params = ["functions", "function_call", "temperature", "temperature", "top_p", "n", "stream", "stop", "max_tokens", "presence_penalty", "frequency_penalty", "logit_bias", "user", "request_timeout", "api_base", "api_version", "api_key", "deployment_id", "organization", "base_url", "default_headers", "timeout"]
|
openai_params = ["functions", "function_call", "temperature", "temperature", "top_p", "n", "stream", "stop", "max_tokens", "presence_penalty", "frequency_penalty", "logit_bias", "user", "request_timeout", "api_base", "api_version", "api_key", "deployment_id", "organization", "base_url", "default_headers", "timeout", "response_format", "seed", "tools", "tool_choice"]
|
||||||
litellm_params = ["metadata", "acompletion", "caching", "return_async", "mock_response", "api_key", "api_version", "api_base", "force_timeout", "logger_fn", "verbose", "custom_llm_provider", "litellm_logging_obj", "litellm_call_id", "use_client", "id", "fallbacks", "azure", "headers", "model_list", "num_retries", "context_window_fallback_dict", "roles", "final_prompt_value", "bos_token", "eos_token", "request_timeout", "complete_response", "self", "max_retries"]
|
litellm_params = ["metadata", "acompletion", "caching", "return_async", "mock_response", "api_key", "api_version", "api_base", "force_timeout", "logger_fn", "verbose", "custom_llm_provider", "litellm_logging_obj", "litellm_call_id", "use_client", "id", "fallbacks", "azure", "headers", "model_list", "num_retries", "context_window_fallback_dict", "roles", "final_prompt_value", "bos_token", "eos_token", "request_timeout", "complete_response", "self", "max_retries"]
|
||||||
default_params = openai_params + litellm_params
|
default_params = openai_params + litellm_params
|
||||||
non_default_params = {k: v for k,v in kwargs.items() if k not in default_params} # model-specific params - pass them straight to the model/provider
|
non_default_params = {k: v for k,v in kwargs.items() if k not in default_params} # model-specific params - pass them straight to the model/provider
|
||||||
|
@ -400,6 +405,10 @@ def completion(
|
||||||
# params to identify the model
|
# params to identify the model
|
||||||
model=model,
|
model=model,
|
||||||
custom_llm_provider=custom_llm_provider,
|
custom_llm_provider=custom_llm_provider,
|
||||||
|
response_format=response_format,
|
||||||
|
seed=seed,
|
||||||
|
tools=tools,
|
||||||
|
tool_choice=tool_choice,
|
||||||
**non_default_params
|
**non_default_params
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1751,6 +1751,10 @@ def get_optional_params( # use the openai defaults
|
||||||
user="",
|
user="",
|
||||||
model=None,
|
model=None,
|
||||||
custom_llm_provider="",
|
custom_llm_provider="",
|
||||||
|
response_format=None,
|
||||||
|
seed=None,
|
||||||
|
tools=None,
|
||||||
|
tool_choice=None,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
# retrieve all parameters passed to the function
|
# retrieve all parameters passed to the function
|
||||||
|
@ -1773,6 +1777,10 @@ def get_optional_params( # use the openai defaults
|
||||||
"user":"",
|
"user":"",
|
||||||
"model":None,
|
"model":None,
|
||||||
"custom_llm_provider":"",
|
"custom_llm_provider":"",
|
||||||
|
"response_format": None,
|
||||||
|
"seed": None,
|
||||||
|
"tools": None,
|
||||||
|
"tool_choice": None
|
||||||
}
|
}
|
||||||
# filter out those parameters that were passed with non-default values
|
# filter out those parameters that were passed with non-default values
|
||||||
non_default_params = {k: v for k, v in passed_params.items() if (k != "model" and k != "custom_llm_provider" and k in default_params and v != default_params[k])}
|
non_default_params = {k: v for k, v in passed_params.items() if (k != "model" and k != "custom_llm_provider" and k in default_params and v != default_params[k])}
|
||||||
|
@ -2166,7 +2174,7 @@ def get_optional_params( # use the openai defaults
|
||||||
temperature = 0.0001 # close to 0
|
temperature = 0.0001 # close to 0
|
||||||
optional_params["temperature"] = temperature
|
optional_params["temperature"] = temperature
|
||||||
else: # assume passing in params for openai/azure openai
|
else: # assume passing in params for openai/azure openai
|
||||||
supported_params = ["functions", "function_call", "temperature", "top_p", "n", "stream", "stop", "max_tokens", "presence_penalty", "frequency_penalty", "logit_bias", "user"]
|
supported_params = ["functions", "function_call", "temperature", "top_p", "n", "stream", "stop", "max_tokens", "presence_penalty", "frequency_penalty", "logit_bias", "user", "response_format", "seed", "tools", "tool_choice"]
|
||||||
_check_valid_arg(supported_params=supported_params)
|
_check_valid_arg(supported_params=supported_params)
|
||||||
optional_params = non_default_params
|
optional_params = non_default_params
|
||||||
# if user passed in non-default kwargs for specific providers/models, pass them along
|
# if user passed in non-default kwargs for specific providers/models, pass them along
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue