先決條件與身份驗證
首先建立帳戶並獲取您的 API 金鑰。使用 使用 Google 帳戶繼續 或在 取得 API 金鑰 頁面。金鑰會立即顯示。無需提供電話號碼。設定您的 OPENAI_API_KEY 環境變數為此值。使用此 base URL 發送所有請求: https://api.uncensoredaiplatform.com/v1.
curl https://api.uncensoredaiplatform.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "set max tokens to 2048 and temperature to 0.7"}]
}'
發送您的第一個請求
向以下網址發送 POST 請求 /v1/chat/completions 使用模型 ID uncensored. 將您的 messages 陣列包含在主體中。API 回傳文字回應。這適用於任何 OpenAI 相容的客戶端。在您的設定中更改基礎 URL 與 API 金鑰。使用此簡單結構來測試連線性。
from openai import OpenAI
client = OpenAI(base_url="https://api.uncensoredaiplatform.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)Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.uncensoredaiplatform.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)