基礎 URL 與驗證
首先使用基礎 URL 進行身份驗證 https://api.googlegeminiuncensored.com/v1. 註冊後,您會立即獲得一個有效的 API 金鑰,可透過 Google 或電子郵件登入使用。將此金鑰用於 Authorization 作為所有後續請求的 Bearer token 標頭。
- 基礎 URL:
https://api.googlegeminiuncensored.com/v1 - 標頭:
Authorization: Bearer YOUR_API_KEY
curl https://api.googlegeminiuncensored.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the top five open source LLMs for local deployment"}]
}'
聊天完成端點
發送文字生成請求至 POST /v1/chat/completions. 此端點接受標準訊息陣列並返回無內容過濾的原始文字回應,適用於合法成人用途。
from openai import OpenAI
client = OpenAI(base_url="https://api.googlegeminiuncensored.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)模型 ID 為 uncensored. 它是運行在我們伺服器上的開放權重模型,與 GPT 或 Gemini 不同。它不在供應商之間路由,也不提供嵌入向量。
串流回應 (SSE)
在請求主體中將 stream: true 在你的請求主體中。API 回傳伺服器發送的事件 (SSE),其中 token 使用數據出現在最後一個區塊。
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.googlegeminiuncensored.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);串流可降低長篇輸出的感知延遲。每個區塊包含部分文字差異。解析最後一個事件以獲取總權杖消耗量,以確保計費透明度。
串流
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)