API dan foydalanish qo'llanmasi
OpenAI Python SDK, cURL yoki har qanday dasturlash tilida ulanishingiz mumkin.
1. cURL orqali so'rov:
curl http://<SERVER-IP>:8090/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-bonsai-SIZNING_KALITINGIZ" -d '{
"messages": [
{"role": "user", "content": "Salom, O‘zbekiston tarixi haqida ma‘lumot ber."}
],
"max_tokens": 500,
"stream": true
}'
1b. Muqobil: x-api-key sarlavhasi (Anthropic-uslubidagi mijozlar):
Bearer o'rniga kalitni x-api-key sarlavhasida ham yuborishingiz mumkin - ikkalasi ham qabul qilinadi.
curl http://<SERVER-IP>:8090/v1/chat/completions -H "Content-Type: application/json" -H "x-api-key: sk-bonsai-SIZNING_KALITINGIZ" -d '{
"messages": [
{"role": "user", "content": "Salom!"}
],
"max_tokens": 100
}'
2. Python (openai kutubxonasi) orqali:
from openai import OpenAI
client = OpenAI(
base_url="http://<SERVER-IP>:8090/v1",
api_key="sk-bonsai-SIZNING_KALITINGIZ"
)
response = client.chat.completions.create(
model="Bonsai-2-27B",
messages=[{"role": "user", "content": "Kvant kompyuterlari qanday ishlaydi?"}],
stream=True
)
for chunk in response:
content = chunk.choices[0].delta.content or ""
print(content, end="", flush=True)