Pydantic AI ကို Shannon ဖြင့် အသုံးပြုခြင်း
Pydantic AI အား Shannon သို့ ညွှန်ထားသော OpenAIProvider ပါသည့် OpenAIChatModel တစ်ခု ပေးပါ၊ ထို့နောက် agent၊ tool နှင့် streaming များသည် Shannon model များပေါ်တွင် run သည်။
- 2026 နို 7 တွင် စမ်းသပ်ထားသည်
- OpenAI Chat Completions
- ခန့်မှန်း 2 မိနစ်
Pydantic AI အကြောင်း
Pydantic AI သည် Pydantic ကို ဖန်တီးသော အဖွဲ့၏ type သတ်မှတ်ထားသော input၊ tool နှင့် output များပါသည့် agent များအတွက် Python framework ဖြစ်သည်။ model ပြန်ပေးသည့်အရာကို စစ်ဆေးပြီး output မကောင်းလျှင် ပြန်ကြိုးစားသည်။ ၎င်း၏ OpenAI provider သည် base URL ကို လက်ခံသဖြင့် agent များသည် Shannon model များပေါ်တွင် tool call နှင့် streaming များဖြင့် run နိုင်သည်။
လိုအပ်သည်များ
- Shannon API key တစ်ခု
- Keys & usage စာမျက်နှာ
- အခြေ URL
-
https://api.shannon-ai.com/v1အဆုံးမှတ်:/v1/chat/completions - အောက်ပါ နမူနာအားလုံးသည် သင့်ရွေးချယ်မှုအတိုင်း ပြောင်းလဲသည်။
သတ်မှတ်ပုံ
-
OpenAI extra ဖြင့် Pydantic AI ကို install လုပ်ပါ
Shellpip install 'pydantic-ai-slim[openai]' -
Model နှင့် agent တစ်ခု ဖန်တီးပါ
Pythonfrom pydantic_ai import Agent from pydantic_ai.models.openai import OpenAIChatModel from pydantic_ai.providers.openai import OpenAIProvider model = OpenAIChatModel( "Kimi-K3-uncensored-NVFP4", provider=OpenAIProvider(base_url="https://api.shannon-ai.com/v1", api_key="YOUR_API_KEY"), ) agent = Agent(model) @agent.tool_plain def get_weather(city: str) -> str: """Weather for a city.""" return f"Sunny, 18 C in {city}" print(agent.run_sync("What is the weather in Oslo?").output) -
စာသားကို stream လုပ်ပါ
Pythonimport asyncio async def main(): async with agent.run_stream("Name three colours a cat can be.") as result: async for text in result.stream_text(delta=True): print(text, end="", flush=True) asyncio.run(main())
အလုပ်လုပ်ကြောင်း စစ်ဆေးပါ
ပို့ရန်: agent နမူနာကို run ပါ။
မြင်ရမည့်အရာ: agent သည် get_weather ကို ခေါ်ပြီး Oslo ၏ နေသာသော ရာသီဥတုဖြင့် ဖြေသည်။
Pydantic AI နှင့် ကိုက်ညီသော model များ
အောက်ပါ id တိုင်းသည် Pydantic AI ၏ လိုအပ်ချက်နှင့် ကိုက်ညီသည်။ ပထမ 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 | မဟုတ် |
သိထားသင့်သည်များ
- Shannon ၏ Chat Completions endpoint အတွက်
OpenAIChatModelကို သုံးပါ။OpenAIResponsesModelသည်/v1/responsesကို သုံးပြီး Shannon သည် ၎င်းကိုလည်း အဖြေများ မသိမ်းဘဲ ပံ့ပိုးသည်။ - tool call တစ်ခုသည် request နှစ်ခု ကုန်သည်- tool ကို တောင်းသော request တစ်ခုနှင့် ၎င်း၏ရလဒ်မှ အဖြေကို ရေးသော request တစ်ခု။
အကြံပြုချက်များ
- Pydantic model ပါသော
output_type=သည် agent ကို စစ်ဆေးပြီး type သတ်မှတ်ထားသော data ပြန်ပေးစေသည်။ OpenAIProviderသည် environment မှOPENAI_BASE_URLနှင့်OPENAI_API_KEYကိုလည်း ဖတ်သည်။agent.run_syncသည် script များတွင် အရိုးရှင်းဆုံး ခေါ်ဆိုမှုဖြစ်ပြီးrun_streamသည် async code တွင် စာသားကို stream လုပ်သည်။
ပြဿနာဖြေရှင်းခြင်း
| လက္ခဏာ | အကြောင်းရင်း | ဖြေရှင်းနည်း |
|---|---|---|
404 Not Found | base_url တွင် /v1 မပါပါ။ | https://api.shannon-ai.com/v1 ကို သုံးပါ။ |
ModuleNotFoundError: openai | slim package ကို OpenAI extra မပါဘဲ install လုပ်ထားသည်။ | pydantic-ai-slim[openai] ကို install လုပ်ပါ။ |
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 ကို အလိုအလျောက် ပြန်မပို့ပါ။ |
မေးခွန်းများ
Pydantic AI သည် Shannon နှင့် အလုပ်လုပ်ပါသလား။
လုပ်ပါသည်၊ OpenAIChatModel နှင့် OpenAIProvider(base_url="https://api.shannon-ai.com/v1") မှတစ်ဆင့် ဖြစ်သည်။
type သတ်မှတ်ထားသော output များ အလုပ်လုပ်ပါသလား။
လုပ်ပါသည်၊ Pydantic AI သည် ၎င်းတို့ကို Shannon model များ ခေါ်သော tool call များမှတစ်ဆင့် ရယူသည်။