diff --git a/docs/my-website/docs/completion/input.md b/docs/my-website/docs/completion/input.md index 4a3264c24..a2cdad5d1 100644 --- a/docs/my-website/docs/completion/input.md +++ b/docs/my-website/docs/completion/input.md @@ -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. -| Provider | functions | function_call | temperature | top_p | n | stream | stop | max_tokens | presence_penalty | frequency_penalty | logit_bias | user | -|---|---|---|---|---|---|---|---|---|---|---|---|---| -|Anthropic| | | ✅ | ✅ | | ✅ | ✅ | ✅ | | | -|OpenAI| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -|Replicate| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅| | | -|Cohere| | | ✅ | ✅ | | ✅ | | ✅| | | ✅ | -|Huggingface| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | -|Openrouter| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | -|AI21| | | | | | | | | | | | -|VertexAI| | | ✅ | ✅ | | ✅ | | ✅ | | | | -|Bedrock| | | ✅ | ✅ | | ✅ | ✅ | ✅ | | | | -|Sagemaker| | | ✅ | | | ✅ | | ✅ | | | | -|TogetherAI| | | ✅ | ✅ | | ✅ | ✅ | ✅ | | ✅ | | -|AlephAlpha| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | -|Palm| | | ✅ | ✅ | | ✅ | | | | | | -|NLP Cloud| | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | -|Petals| | | ✅ | ✅ | | | | ✅ | | | \ No newline at end of file +| Provider | temperature | top_p | n | stream | stop | max_tokens | presence_penalty | frequency_penalty | functions | function_call | +|---|---|---|---|---|---|---|---|---|---|---| +|Anthropic| ✅ | ✅ | | ✅ | ✅ | ✅ | | | | | +|OpenAI| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +|Replicate | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | +|Cohere| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | +|Huggingface| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | +|Openrouter| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +|AI21| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | +|VertexAI| ✅ | ✅ | | ✅ | | ✅ | | | | | +|Bedrock| ✅ | ✅ | | ✅ | ✅ | ✅ | | | | | +|Sagemaker| ✅ | | | ✅ | | ✅ | | | | | +|TogetherAI| ✅ | ✅ | | ✅ | ✅ | ✅ | | | | | +|AlephAlpha| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | +|Palm| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | +|NLP Cloud| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | +|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`. \ No newline at end of file diff --git a/litellm/__init__.py b/litellm/__init__.py index 9afa4aeeb..efb48a7d9 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -15,6 +15,7 @@ token: Optional[ ] = None # for hosted dashboard. Learn more - https://docs.litellm.ai/docs/debugging/hosted_debugging telemetry = True max_tokens = 256 # OpenAI Defaults +drop_params = False retry = True api_key: Optional[str] = None openai_key: Optional[str] = None diff --git a/litellm/__pycache__/utils.cpython-311.pyc b/litellm/__pycache__/utils.cpython-311.pyc index d4014abdd..51ba1a493 100644 Binary files a/litellm/__pycache__/utils.cpython-311.pyc and b/litellm/__pycache__/utils.cpython-311.pyc differ diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index 685ac7b21..e00ea0311 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -323,7 +323,9 @@ def test_completion_cohere(): # commenting for now as the cohere endpoint is bei model="command-nightly", messages=messages, max_tokens=100, + n=1, logit_bias={40: 10}, + stop=["a"], logger_fn=logger_fn ) # 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: pytest.fail(f"Error occurred: {e}") -# test_completion_cohere() +test_completion_cohere() def test_completion_openai(): diff --git a/litellm/utils.py b/litellm/utils.py index 3843d428c..9c70575f8 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -987,7 +987,7 @@ def get_optional_params( # use the openai defaults pass else: 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 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 elif custom_llm_provider == "cohere": ## 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) # handle cohere params if stream: @@ -1018,10 +1018,18 @@ def get_optional_params( # use the openai defaults optional_params["temperature"] = temperature if max_tokens: optional_params["max_tokens"] = max_tokens + if n: + optional_params["num_generations"] = n if logit_bias != {}: optional_params["logit_bias"] = logit_bias if 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": ## check if unsupported param passed in 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: optional_params["max_tokens"] = max_tokens 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: - optional_params["stop"] = stop #TG AI expects a list, example ["\n\n\n\n","<|endoftext|>"] + optional_params["stop"] = stop elif custom_llm_provider == "ai21": ## check if unsupported param passed in 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} if 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 - supported_params = ["temperature", "top_p", "stream"] + supported_params = ["temperature", "top_p", "stream", "n", "stop", "max_tokens"] _check_valid_arg(supported_params=supported_params) if temperature: @@ -1114,6 +1122,12 @@ def get_optional_params( # use the openai defaults optional_params["top_p"] = top_p if 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 ( custom_llm_provider == "vertex_ai" ): @@ -1241,7 +1255,7 @@ def get_optional_params( # use the openai defaults if stop: optional_params["stop_sequences"] = stop 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) # max_new_tokens=1,temperature=0.9, top_p=0.6 if max_tokens: @@ -1250,6 +1264,8 @@ def get_optional_params( # use the openai defaults optional_params["temperature"] = temperature if top_p: optional_params["top_p"] = top_p + if stream: + optional_params["stream"] = stream 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"] _check_valid_arg(supported_params=supported_params) diff --git a/pyproject.toml b/pyproject.toml index 44deaba6c..255614680 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "litellm" -version = "0.1.818" +version = "0.1.819" description = "Library to easily interface with LLM API providers" authors = ["BerriAI"] license = "MIT License"