AI21
LiteLLM 支持以下 AI21 模型
jamba-1.5-mini
jamba-1.5-large
j2-light
j2-mid
j2-ultra
提示
我们支持所有 AI21 模型,只需在发送 litellm 请求时将 model=ai21/<any-model-on-ai21>
作为前缀设置即可。在此查看所有 LiteLLM 支持的 AI21 模型 这里
API 密钥
import os
os.environ["AI21_API_KEY"] = "your-api-key"
LiteLLM Python SDK 用法
使用示例
from litellm import completion
# set env variable
os.environ["AI21_API_KEY"] = "your-api-key"
messages = [{"role": "user", "content": "Write me a poem about the blue sky"}]
completion(model="ai21/jamba-1.5-mini", messages=messages)
LiteLLM 代理服务器用法
以下是如何使用 LiteLLM 代理服务器调用 AI21 模型
修改 config.yaml
model_list:
- model_name: my-model
litellm_params:
model: ai21/<your-model-name> # add ai21/ prefix to route as ai21 provider
api_key: api-key # api key to send your model
启动代理
$ litellm --config /path/to/config.yaml
发送请求到 LiteLLM 代理服务器
- OpenAI Python v1.0.0+
- curl
import openai
client = openai.OpenAI(
api_key="sk-1234", # pass litellm proxy key, if you're using virtual keys
base_url="http://0.0.0.0:4000" # litellm-proxy-base url
)
response = client.chat.completions.create(
model="my-model",
messages = [
{
"role": "user",
"content": "what llm are you"
}
],
)
print(response)curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data '{
"model": "my-model",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
],
}'
支持的 OpenAI 参数
参数 | 类型 | AI21 等效参数 |
---|---|---|
tools | 可选[列表] | tools |
response_format | 可选[字典] | response_format |
max_tokens | 可选[整数] | max_tokens |
temperature | 可选[浮点数] | temperature |
top_p | 可选[浮点数] | top_p |
stop | 可选[联合类型[字符串, 列表]] | stop |
n | 可选[整数] | n |
stream | 可选[布尔值] | stream |
seed | 可选[整数] | seed |
tool_choice | 可选[字符串] | tool_choice |
user | 可选[字符串] | user |
支持的 AI21 参数
参数 | 类型 | AI21 等效参数 |
---|---|---|
documents | 可选[列表[字典]] | documents |
传递 AI21 特有参数 - documents
LiteLLM 允许您将所有 AI21 特有参数传递给 litellm.completion
函数。以下是向 litellm.completion
函数传递 documents
参数的示例。
- LiteLLM Python SDK
- LiteLLM 代理服务器
response = await litellm.acompletion(
model="jamba-1.5-large",
messages=[{"role": "user", "content": "what does the document say"}],
documents = [
{
"content": "hello world",
"metadata": {
"source": "google",
"author": "ishaan"
}
}
]
)
import openai
client = openai.OpenAI(
api_key="sk-1234", # pass litellm proxy key, if you're using virtual keys
base_url="http://0.0.0.0:4000" # litellm-proxy-base url
)
response = client.chat.completions.create(
model="my-model",
messages = [
{
"role": "user",
"content": "what llm are you"
}
],
extra_body = {
"documents": [
{
"content": "hello world",
"metadata": {
"source": "google",
"author": "ishaan"
}
}
]
}
)
print(response)
提示
我们支持所有 AI21 模型,只需在发送 litellm 请求时将 model=ai21/<any-model-on-ai21>
作为前缀设置即可 在此查看所有 LiteLLM 支持的 AI21 模型 这里
AI21 模型
模型名称 | 函数调用 | 必需的操作系统变量 |
---|---|---|
jamba-1.5-mini | completion('jamba-1.5-mini', messages) | os.environ['AI21_API_KEY'] |
jamba-1.5-large | completion('jamba-1.5-large', messages) | os.environ['AI21_API_KEY'] |
j2-light | completion('j2-light', messages) | os.environ['AI21_API_KEY'] |
j2-mid | completion('j2-mid', messages) | os.environ['AI21_API_KEY'] |
j2-ultra | completion('j2-ultra', messages) | os.environ['AI21_API_KEY'] |