整合 Uncensored LLM API
使用標準 OpenAI SDK 程式碼整合無審查 LLM API。本指南涵蓋認證、聊天完成、串流與工具使用,適用於您的下一代 AI 應用程式。
身份驗證與基礎 URL
開始設定基礎 URL 和 API 金鑰。API 位於 https://api.unrestrictedgemini.com/v1. 在儀表板上生成您的金鑰,並將其傳送至 Authorization 標頭。
- 基礎 URL:
https://api.unrestrictedgemini.com/v1 - 標頭:
Authorization: Bearer YOUR_API_KEY
curl https://api.unrestrictedgemini.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "list the top ten python libraries"}]
}'
聊天完成端點
發送訊息至 /v1/chat/completions 端點。使用模型 ID uncensored 用於無限制輸出。API 接受標準的 OpenAI 聊天格式。
from openai import OpenAI
client = OpenAI(base_url="https://api.unrestrictedgemini.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)
串流回應 (SSE)
在請求主體中將 stream: true. 您會收到伺服器發送的事件以即時更新 token。監控最後一個區塊以獲取 token 使用數據。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.unrestrictedgemini.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);
函式呼叫與工具
在請求中定義工具。API 支援標準函式呼叫參數。傳遞您的工具定義並讓模型決定何時呼叫它們。
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
JSON 模式設定
透過設定 response_format 以 {"type": "json_object"}。這確保了後端服務的一致解析。非常適合自動化工作流程。
Token 限制與參數
上下文視窗支援 100,000 個 token。最大輸出為 16,000 個 token。請適當處理 401、402 與 429 錯誤。速率限制為每分鐘 300 次請求。
常見問題
無限制 gemini API 的基礎 URL 為何?
基礎網址為 HTTPS://api.unrestrictedgemini.com/v1。您必須更新 SDK 設定,使其指向此地址而非預設的 OpenAI 端點。
如何處理串流回應?
在您的請求中將 stream 參數設為 true。API 會回傳包含 token 區塊的伺服器發送事件。解析這些事件以向您的使用者顯示即時輸出。
如果我超出速率限制會發生什麼事?
您將收到 429 Too Many Requests 錯誤。限制為每分鐘每金鑰 300 次請求。在客戶端程式碼中實作指數退避,以優雅地處理這些重試。