URL ฐานและการตรวจสอบสิทธิ์
เริ่มต้นด้วยการตรวจสอบสิทธิ์ด้วย URL พื้นฐาน https://api.googlegeminiuncensored.com/v1. คุณได้รับคีย์ API ที่ใช้งานได้ทันทีหลังจากลงทะเบียนผ่าน Google หรืออีเมล ใช้คีย์นี้ใน Authorization header เป็น Bearer token สำหรับคำขอทั้งหมดในลำดับถัดไป
- Base 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"}]
}'
จุดจบ API Chat Completions
ส่งคำขอสร้างข้อความไปยัง 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)รหัสโมเดลคือ uncensored. มันเป็นโมเดลโอเพนเวตที่ทำงานบนเซิร์ฟเวอร์ของเรา ซึ่งแตกต่างจาก GPT หรือ Gemini มันไม่เปลี่ยนเส้นทางระหว่างผู้ขายหรือเสนอ embeddings
การตอบกลับแบบสตรีมมิ่ง (SSE)
เปิดใช้งานการสตรีมโดยตั้งค่า stream: true ในบอดีคำขอของคุณ API จะส่งคืนเหตุการณ์ที่ส่งจากเซิร์ฟเวอร์ (SSE) โดยข้อมูลการใช้งานโทเค็นจะปรากฏในชิ้นสุดท้าย
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)