Điều kiện tiên quyết và Xác thực
Bắt đầu bằng cách tạo tài khoản và tạo khóa API của bạn. Sử dụng Tiếp tục với Google hoặc cung cấp email và mật khẩu trên Lấy khóa API trang. Khóa xuất hiện ngay lập tức. Không cần số điện thoại. Đặt OPENAI_API_KEY environment variable to this value. Sử dụng URL cơ sở này cho tất cả các yêu cầu: 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"}]
}'
Gửi yêu cầu đầu tiên của bạn
Gửi yêu cầu POST đến /v1/chat/completions với ID mô hình uncensored. Bao gồm mảng messages của bạn trong phần thân yêu cầu. API trả về phản hồi văn bản. Điều này hoạt động với bất kỳ khách hàng tương thích OpenAI nào. Thay đổi URL cơ sở và khóa API trong cấu hình của bạn. Sử dụng cấu trúc đơn giản này để kiểm tra kết nối.
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);Phát trực tiếp
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)