跳至主要內容

GradientAI

https://digitalocean.com/products/gradientai

LiteLLM 原生支援 GradientAI 模型。 若要使用 GradientAI 模型,請在您的 LiteLLM 請求中將其指定為 gradient_ai/<model-name>。

API 金鑰與端點​

將您的 API 金鑰設為環境變數。請求預設會送至無伺服器推論端點 https://inference.do-ai.run/v1/chat/completions,因此不需要端點變數:

import os
os.environ['GRADIENT_AI_API_KEY'] = "your-api-key"

若要改為呼叫 GradientAI 代理程式,請將 GRADIENT_AI_AGENT_ENDPOINT(或傳入 api_base)設為該代理程式的基底 URL。LiteLLM 會在其後附加 /api/v1/chat/completions,因此不要包含路徑:

os.environ['GRADIENT_AI_AGENT_ENDPOINT'] = "https://<agent-id>.agents.do-ai.run"  # optional, agents only

範例用法​

from litellm import completion
import os

os.environ['GRADIENT_AI_API_KEY'] = "your-api-key"
response = completion(
model="gradient_ai/model-name",
messages=[
{"role": "user", "content": "Hello, how are you?"}
],
)
print(response.choices[0].message.content)

串流範例​

from litellm import completion
import os

os.environ['GRADIENT_AI_API_KEY'] = "your-api-key"
response = completion(
model="gradient_ai/model-name",
messages=[
{"role": "user", "content": "Write a story about a robot learning to love"}
],
stream=True,
)

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

支援的參數​

參數類型說明
temperaturefloat控制隨機性(0.0-2.0)
top_pfloat核心採樣參數(0.0-1.0)
max_tokensint要生成的最大 tokens 數
max_completion_tokensintmax_tokens 的替代項
streambool是否串流回應
kint從知識庫傳回的前幾個結果
retrieval_methodstring擷取策略(rewrite/step_back/sub_queries/none)
frequency_penaltyfloat對重複 tokens 施加懲罰(-2.0 到 2.0)
presence_penaltyfloat根據出現次數對 tokens 施加懲罰(-2.0 到 2.0)
stopstring/list停止生成的序列
kb_filtersList[Dict]知識庫擷取篩選器
instruction_overridestring覆寫代理程式的預設指令
include_retrieval_infobool包含文件擷取中繼資料
include_guardrails_infobool包含防護欄觸發中繼資料
provide_citationsbool在回應中包含引用

更多詳情請參閱 DigitalOcean GradientAI 文件。

LiteLLM Enterprise
為正式環境打造的 SSO/SAML、稽核記錄、支出追蹤、多團隊管理與防護欄。
深入瞭解 →