OpenAI SDK ကို Shannon ဖြင့် အသုံးပြုခြင်း
သင်အသုံးပြုနေပြီးသော OpenAI SDK ကို ဆက်သုံးပါ- base URL နှင့် key ကို ပြောင်းပြီး Shannon model id တစ်ခု ရွေးပါ။
- 2026 နို 7 တွင် စမ်းသပ်ထားသည်
- OpenAI Chat Completions
- ခန့်မှန်း 1 မိနစ်
OpenAI SDK အကြောင်း
Python နှင့် Node.js အတွက် တရားဝင် OpenAI library များသည် code မှ chat API ကို ခေါ်ရန် အသုံးအများဆုံး နည်းလမ်းဖြစ်သည်။ ၎င်းတို့သည် base URL ကို လက်ခံသဖြင့် code တူတူပင် Shannon နှင့် အလုပ်လုပ်သည်- chat completions၊ streaming၊ tool call များနှင့် Responses API။
လိုအပ်သည်များ
- Shannon API key တစ်ခု
- Keys & usage စာမျက်နှာ
- အခြေ URL
-
https://api.shannon-ai.com/v1အဆုံးမှတ်:/v1/chat/completions - အောက်ပါ နမူနာအားလုံးသည် သင့်ရွေးချယ်မှုအတိုင်း ပြောင်းလဲသည်။
သတ်မှတ်ပုံ
-
SDK ကို install လုပ်ပါ
pip install openainpm install openai -
Shannon သို့ ညွှန်ပါ
client သာ ပြောင်းသည်။ SDK များသည် environment မှ
OPENAI_BASE_URLနှင့်OPENAI_API_KEYကိုလည်း ဖတ်သည်။from openai import OpenAI client = OpenAI(base_url="https://api.shannon-ai.com/v1", api_key="YOUR_API_KEY") stream = client.chat.completions.create( model="Kimi-K3-uncensored-NVFP4", messages=[{"role": "user", "content": "Name three colours a cat can be."}], stream=True, ) for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.shannon-ai.com/v1", apiKey: "YOUR_API_KEY" }); const stream = await client.chat.completions.create({ model: "Kimi-K3-uncensored-NVFP4", messages: [{ role: "user", content: "Name three colours a cat can be." }], stream: true, }); for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? ""); -
Tool များကို ခေါ်ပါ
Tool များသည် OpenAI နှင့်တူစွာ အလုပ်လုပ်သည်- အဖြေသည်
finish_reason: "tool_calls"ဖြင့် ပြီးဆုံးပြီး ခေါ်ဆိုမှုများသည်message.tool_callsတွင် ရှိသည်။Pythontools = [{"type": "function", "function": { "name": "get_weather", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}, }}] r = client.chat.completions.create( model="Kimi-K3-uncensored-NVFP4", messages=[{"role": "user", "content": "What is the weather in Oslo?"}], tools=tools, ) print(r.choices[0].message.tool_calls[0].function.arguments) # {"city": "Oslo"}
အလုပ်လုပ်ကြောင်း စစ်ဆေးပါ
ပို့ရန်: streaming နမူနာကို run ပါ။
မြင်ရမည့်အရာ: အရောင်များသည် stream ဝင်လာသည်နှင့်အမျှ ပုံနှိပ်ပေါ်လာသည်၊ ဥပမာ “ကြောင်များသည် အနက်၊ အဖြူ နှင့် လိမ္မော်ရောင် ဖြစ်နိုင်သည်။”
OpenAI SDK နှင့် ကိုက်ညီသော model များ
အောက်ပါ id တိုင်းသည် OpenAI SDK ၏ လိုအပ်ချက်နှင့် ကိုက်ညီသည်။ ပထမ id သည် code နမူနာများတွင် default ဖြစ်သည်။
| မော်ဒယ် ID | Context အရွယ် | အများဆုံး output | ပုံ ထည့်သွင်းမှု |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | ဟုတ် |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | ဟုတ် |
shannon-3 | 196,608 | 65,536 | ဟုတ် |
shannon-coder-1 | 131,072 | 65,536 | မဟုတ် |
သိထားသင့်သည်များ
client.responses.create(...)လည်း အလုပ်လုပ်သည်။ Shannon သည် အဖြေများကို မသိမ်းဘဲ/v1/responsesကို ပံ့ပိုးသဖြင့် အကြိမ်တိုင်း စကားဝိုင်းတစ်ခုလုံးကို ပို့ပါ။- Reasoning သည် chunk တစ်ခုစီ၏
deltaထဲတွင်content၏ ဘေးမှreasoning_contentအဖြစ် ရောက်လာသည်။ /v1/embeddingsမရှိပါ။ retrieval အတွက် သီးခြား embedding model ကို သုံးပါ။
အကြံပြုချက်များ
- environment တွင်
OPENAI_BASE_URLနှင့်OPENAI_API_KEYကို သတ်မှတ်ထားလျှင် client သည် argument မလိုဘဲ ယူသုံးသဖြင့် ရှိပြီးသား code ကို ပြောင်းစရာ မလိုပါ။ - အဖြေရှည်များအတွက်
stream=Trueပေးပါ။ စာသားနှင့် reasoning တို့ ရေးသလို ရောက်လာမည်။ - client တွင်
max_retriesနှင့်timeoutကို သတ်မှတ်ပါ- SDK သည်429နှင့်5xxအဖြေများကို ကိုယ်တိုင် ပြန်ကြိုးစားသည်။ - ခေါ်ဆိုမှုတစ်ခုစီက cache လုပ်ထားသော token များ အပါအဝင် token ဘယ်လောက်သုံးခဲ့သည်ကို မှတ်တမ်းတင်ရန် response တိုင်းတွင်
usageကို ဖတ်ပါ။
ပြဿနာဖြေရှင်းခြင်း
| လက္ခဏာ | အကြောင်းရင်း | ဖြေရှင်းနည်း |
|---|---|---|
404 Not Found | base_url တွင် /v1 မပါပါ။ | https://api.shannon-ai.com/v1 ကို သုံးပါ။ |
400 unknown model | gpt-4o ကဲ့သို့ OpenAI model အမည်။ | GET /v1/models မှ Shannon id တစ်ခုကို သုံးပါ။ |
401 Unauthorized | Key မရှိခြင်း၊ စာလုံးပေါင်းမှားခြင်း သို့မဟုတ် လဲလှယ်ပြီးသွားခြင်း ဖြစ်သည်။ | Keys & usage မှ key ကို ထပ်မံကူးယူပါ။ ၎င်းသည် sk- ဖြင့် စတင်သည်။ |
context_length_exceeded သို့မဟုတ် "prompt is too long" စာတို | စကားပြောဆိုမှုသည် model ၏ context window ထက် ပိုရှည်နေသည်။ | chat အသစ် စတင်ပါ၊ tool ကို ချုံ့ခွင့်ပေးပါ သို့မဟုတ် window ပိုကြီးသော model ကို ရွေးပါ။ |
insufficient_quota | သင့် လက်ကျန်ငွေသည် request အတွက် ပေးချေရန် မလုံလောက်ပါ။ | Top up ပြုလုပ်ပါ သို့မဟုတ် plan ပြောင်းပါ။ request ကို အလိုအလျောက် ပြန်မပို့ပါ။ |
မေးခွန်းများ
Shannon သည် OpenAI API ကို တိုက်ရိုက်အစားထိုးနိုင်ပါသလား။
chat completions၊ Responses API၊ streaming၊ tool များနှင့် structured output များအတွက် ဟုတ်ပါသည်- base_url၊ key နှင့် model id ကို ပြောင်းလိုက်ရုံဖြစ်သည်။
Anthropic SDK လည်း အလုပ်လုပ်ပါသလား။
လုပ်ပါသည်- Anthropic(base_url="https://api.shannon-ai.com", api_key=...) သည် /v1/messages နှင့် ဆက်သွယ်သည်။