provider_specific_params
设置提供商特定的参数
目标:在 OpenAI + Cohere 中设置最大 token 数
1. 通过 completion 调用
LiteLLM 会自动将 max_tokens 翻译成该特定模型提供商所遵循的命名约定。
from litellm import completion
import os
## set ENV variables
os.environ["OPENAI_API_KEY"] = "your-openai-key"
os.environ["COHERE_API_KEY"] = "your-cohere-key"
messages = [{ "content": "Hello, how are you?","role": "user"}]
# openai call
response = completion(model="gpt-3.5-turbo", messages=messages, max_tokens=100)
# cohere call
response = completion(model="command-nightly", messages=messages, max_tokens=100)
print(response)
2. 通过提供商特定的配置
对于 LiteLLM 上的每个提供商,我们都获取了他们特定的参数(遵循他们的命名约定等)。您只需通过 litellm.<provider_name>Config
调出该提供商来为其设置参数。
所有提供商配置都是类型化的并带有 docstring,因此您应该在 VSCode 中看到它们自动补全,并附带解释其含义。
以下是通过提供商配置设置最大 token 数的示例。