跳至主要內容

Amazon Nova

屬性詳細資訊
說明Amazon Nova 是一系列由 Amazon 建立的基礎模型,提供前沿智慧與業界領先的價格效能。
LiteLLM 提供者路由amazon_nova/
提供者文件Amazon Nova ↗
支援的 OpenAI 端點/chat/completions, v1/responses
其他支援的端點v1/messages, /generateContent

驗證

Amazon Nova 使用 API 金鑰驗證。您可以從 Amazon Nova developer console ↗ 取得您的 API 金鑰。

export AMAZON_NOVA_API_KEY="your-api-key"

用法

import os
from litellm import completion

# Set your API key
os.environ["AMAZON_NOVA_API_KEY"] = "your-api-key"

response = completion(
model="amazon_nova/nova-micro-v1",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello, how are you?"}
]
)

print(response)

支援的模型

模型名稱用法上下文視窗
Nova Microcompletion(model="amazon_nova/nova-micro-v1", messages=messages)128K tokens
Nova Litecompletion(model="amazon_nova/nova-lite-v1", messages=messages)300K tokens
Nova Procompletion(model="amazon_nova/nova-pro-v1", messages=messages)300K tokens
Nova Premiercompletion(model="amazon_nova/nova-premier-v1", messages=messages)1M tokens

用法 - 串流

import os
from litellm import completion

os.environ["AMAZON_NOVA_API_KEY"] = "your-api-key"

response = completion(
model="amazon_nova/nova-micro-v1",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Tell me about machine learning"}
],
stream=True
)

for chunk in response:
print(chunk.choices[0].delta.content or "", end="")

用法 - 函式呼叫 / 工具使用

import os
from litellm import completion

os.environ["AMAZON_NOVA_API_KEY"] = "your-api-key"

tools = [
{
"type": "function",
"function": {
"name": "getCurrentWeather",
"description": "Get the current weather in a given city",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. San Francisco, CA"
}
},
"required": ["location"]
}
}
}
]

response = completion(
model="amazon_nova/nova-micro-v1",
messages=[
{"role": "user", "content": "What's the weather like in San Francisco?"}
],
tools=tools
)

print(response)

設定 temperature、top_p 等

import os
from litellm import completion

os.environ["AMAZON_NOVA_API_KEY"] = "your-api-key"

response = completion(
model="amazon_nova/nova-pro-v1",
messages=[
{"role": "user", "content": "Write a creative story"}
],
temperature=0.8,
max_tokens=500,
top_p=0.9
)

print(response)

模型比較

模型適用情境速度成本上下文
Nova Micro簡單任務、高吞吐量最快最低128K
Nova Lite平衡效能300K
Nova Pro複雜推理中等中等300K
Nova Premier最先進的任務較慢較高1M

錯誤處理

常見錯誤代碼及其意義:

  • 401 Unauthorized: 無效的 API 金鑰
  • 429 Too Many Requests: 已超過速率限制
  • 400 Bad Request: 無效的請求格式
  • 500 Internal Server Error: 服務暫時無法使用