add additional param mapping

This commit is contained in:
Krrish Dholakia 2023-10-03 21:56:00 -07:00
parent b5fc04c315
commit 95899bf60e
6 changed files with 47 additions and 26 deletions

View file

@ -62,20 +62,22 @@ E.g. If Anthropic supports top_k, then `completion(model="claude-2", .., top_k=3
This list is constantly being updated. This list is constantly being updated.
| Provider | functions | function_call | temperature | top_p | n | stream | stop | max_tokens | presence_penalty | frequency_penalty | logit_bias | user | | Provider | temperature | top_p | n | stream | stop | max_tokens | presence_penalty | frequency_penalty | functions | function_call |
|---|---|---|---|---|---|---|---|---|---|---|---|---| |---|---|---|---|---|---|---|---|---|---|---|
|Anthropic| | | ✅ | ✅ | | ✅ | ✅ | ✅ | | | |Anthropic| ✅ | ✅ | | ✅ | ✅ | ✅ | | | | |
|OpenAI| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |OpenAI| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|Replicate| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅| | | |Replicate | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | |
|Cohere| | | ✅ | ✅ | | ✅ | | ✅| | | ✅ | |Cohere| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
|Huggingface| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | |Huggingface| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | |
|Openrouter| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |Openrouter| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|AI21| | | | | | | | | | | | |AI21| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | |
|VertexAI| | | ✅ | ✅ | | ✅ | | ✅ | | | | |VertexAI| ✅ | ✅ | | ✅ | | ✅ | | | | |
|Bedrock| | | ✅ | ✅ | | ✅ | ✅ | ✅ | | | | |Bedrock| ✅ | ✅ | | ✅ | ✅ | ✅ | | | | |
|Sagemaker| | | ✅ | | | ✅ | | ✅ | | | | |Sagemaker| ✅ | | | ✅ | | ✅ | | | | |
|TogetherAI| | | ✅ | ✅ | | ✅ | ✅ | ✅ | | ✅ | | |TogetherAI| ✅ | ✅ | | ✅ | ✅ | ✅ | | | | |
|AlephAlpha| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | |AlephAlpha| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | |
|Palm| | | ✅ | ✅ | | ✅ | | | | | | |Palm| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | |
|NLP Cloud| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | |NLP Cloud| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | |
|Petals| | | ✅ | ✅ | | | | ✅ | | | |Petals| ✅ | ✅ | | ✅ | ✅ | | | | | |
By default, LiteLLM raises an exception if the param being passed in isn't supported. However, if you want to just drop the param, instead of raising an exception, just set `litellm.drop_params = True`.

View file

@ -15,6 +15,7 @@ token: Optional[
] = None # for hosted dashboard. Learn more - https://docs.litellm.ai/docs/debugging/hosted_debugging ] = None # for hosted dashboard. Learn more - https://docs.litellm.ai/docs/debugging/hosted_debugging
telemetry = True telemetry = True
max_tokens = 256 # OpenAI Defaults max_tokens = 256 # OpenAI Defaults
drop_params = False
retry = True retry = True
api_key: Optional[str] = None api_key: Optional[str] = None
openai_key: Optional[str] = None openai_key: Optional[str] = None

View file

@ -323,7 +323,9 @@ def test_completion_cohere(): # commenting for now as the cohere endpoint is bei
model="command-nightly", model="command-nightly",
messages=messages, messages=messages,
max_tokens=100, max_tokens=100,
n=1,
logit_bias={40: 10}, logit_bias={40: 10},
stop=["a"],
logger_fn=logger_fn logger_fn=logger_fn
) )
# Add any assertions here to check the response # Add any assertions here to check the response
@ -337,7 +339,7 @@ def test_completion_cohere(): # commenting for now as the cohere endpoint is bei
except Exception as e: except Exception as e:
pytest.fail(f"Error occurred: {e}") pytest.fail(f"Error occurred: {e}")
# test_completion_cohere() test_completion_cohere()
def test_completion_openai(): def test_completion_openai():

View file

@ -987,7 +987,7 @@ def get_optional_params( # use the openai defaults
pass pass
else: else:
unsupported_params.append(k) unsupported_params.append(k)
if unsupported_params: if unsupported_params and not litellm.drop_params:
raise ValueError("LiteLLM.Exception: Unsupported parameters passed: {}".format(', '.join(unsupported_params))) raise ValueError("LiteLLM.Exception: Unsupported parameters passed: {}".format(', '.join(unsupported_params)))
## raise exception if provider doesn't support passed in param ## raise exception if provider doesn't support passed in param
@ -1009,7 +1009,7 @@ def get_optional_params( # use the openai defaults
optional_params["max_tokens_to_sample"] = max_tokens optional_params["max_tokens_to_sample"] = max_tokens
elif custom_llm_provider == "cohere": elif custom_llm_provider == "cohere":
## check if unsupported param passed in ## check if unsupported param passed in
supported_params = ["stream", "temperature", "max_tokens", "logit_bias", "top_p"] supported_params = ["stream", "temperature", "max_tokens", "logit_bias", "top_p", "frequency_penalty", "presence_penalty", "stop"]
_check_valid_arg(supported_params=supported_params) _check_valid_arg(supported_params=supported_params)
# handle cohere params # handle cohere params
if stream: if stream:
@ -1018,10 +1018,18 @@ def get_optional_params( # use the openai defaults
optional_params["temperature"] = temperature optional_params["temperature"] = temperature
if max_tokens: if max_tokens:
optional_params["max_tokens"] = max_tokens optional_params["max_tokens"] = max_tokens
if n:
optional_params["num_generations"] = n
if logit_bias != {}: if logit_bias != {}:
optional_params["logit_bias"] = logit_bias optional_params["logit_bias"] = logit_bias
if top_p: if top_p:
optional_params["p"] = top_p optional_params["p"] = top_p
if frequency_penalty:
optional_params["frequency_penalty"] = frequency_penalty
if presence_penalty:
optional_params["presence_penalty"] = presence_penalty
if stop:
optional_params["stop_sequences"] = stop
elif custom_llm_provider == "replicate": elif custom_llm_provider == "replicate":
## check if unsupported param passed in ## check if unsupported param passed in
supported_params = ["stream", "temperature", "max_tokens", "top_p", "stop", "seed"] supported_params = ["stream", "temperature", "max_tokens", "top_p", "stop", "seed"]
@ -1079,9 +1087,9 @@ def get_optional_params( # use the openai defaults
if max_tokens: if max_tokens:
optional_params["max_tokens"] = max_tokens optional_params["max_tokens"] = max_tokens
if frequency_penalty: if frequency_penalty:
optional_params["frequency_penalty"] = frequency_penalty # TODO: Check if should be repetition penalty optional_params["repetition_penalty"] = frequency_penalty # https://docs.together.ai/reference/inference
if stop: if stop:
optional_params["stop"] = stop #TG AI expects a list, example ["\n\n\n\n","<|endoftext|>"] optional_params["stop"] = stop
elif custom_llm_provider == "ai21": elif custom_llm_provider == "ai21":
## check if unsupported param passed in ## check if unsupported param passed in
supported_params = ["stream", "n", "temperature", "max_tokens", "top_p", "stop", "frequency_penalty", "presence_penalty"] supported_params = ["stream", "n", "temperature", "max_tokens", "top_p", "stop", "frequency_penalty", "presence_penalty"]
@ -1103,9 +1111,9 @@ def get_optional_params( # use the openai defaults
optional_params["frequencyPenalty"] = {"scale": frequency_penalty} optional_params["frequencyPenalty"] = {"scale": frequency_penalty}
if presence_penalty: if presence_penalty:
optional_params["presencePenalty"] = {"scale": presence_penalty} optional_params["presencePenalty"] = {"scale": presence_penalty}
elif custom_llm_provider == "palm": elif custom_llm_provider == "palm": # https://developers.generativeai.google/tutorials/curl_quickstart
## check if unsupported param passed in ## check if unsupported param passed in
supported_params = ["temperature", "top_p", "stream"] supported_params = ["temperature", "top_p", "stream", "n", "stop", "max_tokens"]
_check_valid_arg(supported_params=supported_params) _check_valid_arg(supported_params=supported_params)
if temperature: if temperature:
@ -1114,6 +1122,12 @@ def get_optional_params( # use the openai defaults
optional_params["top_p"] = top_p optional_params["top_p"] = top_p
if stream: if stream:
optional_params["stream"] = stream optional_params["stream"] = stream
if n:
optional_params["candidate_count"] = n
if stop:
optional_params["stopSequences"] = stop
if max_tokens:
optional_params["maxOutputTokens"] = max_tokens
elif ( elif (
custom_llm_provider == "vertex_ai" custom_llm_provider == "vertex_ai"
): ):
@ -1241,7 +1255,7 @@ def get_optional_params( # use the openai defaults
if stop: if stop:
optional_params["stop_sequences"] = stop optional_params["stop_sequences"] = stop
elif model in litellm.petals_models or custom_llm_provider == "petals": elif model in litellm.petals_models or custom_llm_provider == "petals":
supported_params = ["max_tokens", "temperature", "top_p"] supported_params = ["max_tokens", "temperature", "top_p", "stream"]
_check_valid_arg(supported_params=supported_params) _check_valid_arg(supported_params=supported_params)
# max_new_tokens=1,temperature=0.9, top_p=0.6 # max_new_tokens=1,temperature=0.9, top_p=0.6
if max_tokens: if max_tokens:
@ -1250,6 +1264,8 @@ def get_optional_params( # use the openai defaults
optional_params["temperature"] = temperature optional_params["temperature"] = temperature
if top_p: if top_p:
optional_params["top_p"] = top_p optional_params["top_p"] = top_p
if stream:
optional_params["stream"] = stream
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", "deployment_id"] supported_params = ["functions", "function_call", "temperature", "top_p", "n", "stream", "stop", "max_tokens", "presence_penalty", "frequency_penalty", "logit_bias", "user", "deployment_id"]
_check_valid_arg(supported_params=supported_params) _check_valid_arg(supported_params=supported_params)

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "litellm" name = "litellm"
version = "0.1.818" version = "0.1.819"
description = "Library to easily interface with LLM API providers" description = "Library to easily interface with LLM API providers"
authors = ["BerriAI"] authors = ["BerriAI"]
license = "MIT License" license = "MIT License"