Lo Pydantic AI pẹ̀lú Shannon
Fún Pydantic AI ní OpenAIChatModel pẹ̀lú OpenAIProvider tí a tọ́ka sí Shannon; àwọn agent, tool àti streaming yóò ṣiṣẹ́ lórí àwọn model Shannon.
- A dán an wò 7 Oṣù Bélú 2026
- OpenAI Chat Completions
- Nǹkan bí ìṣẹ́jú 2
Nípa Pydantic AI
Pydantic AI jẹ́ framework Python fún àwọn agent pẹ̀lú input, tool àti output onírú, láti ọ̀dọ̀ ẹgbẹ́ tó wà lẹ́yìn Pydantic. Ó ń fìdí ohun tí model dá padà múlẹ̀, ó sì ń tún gbìyànjú nígbà tí output kò bá dára. Olùpèsè OpenAI rẹ̀ gba base URL, nítorí náà àwọn agent lè ṣiṣẹ́ lórí àwọn model Shannon pẹ̀lú tool call àti streaming.
Ohun tí o nílò
- API key Shannon kan
- Àwọn key àti ìlò
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Gbogbo àpẹẹrẹ code nísàlẹ̀ ń tẹ̀lé àṣàyàn rẹ.
Ṣètò rẹ̀
-
Fi Pydantic AI sílẹ̀ pẹ̀lú OpenAI extra
Shellpip install 'pydantic-ai-slim[openai]' -
Ṣẹ̀dá model náà àti agent kan
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) -
Ṣe streaming ọ̀rọ̀
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())
Ṣàyẹ̀wò pé ó ń ṣiṣẹ́
Fi ránṣẹ́: Ṣiṣẹ́ àpẹẹrẹ agent náà.
Ó yẹ kí o rí: Agent náà pe get_weather ó sì dáhùn pẹ̀lú ojú-ọjọ́ tó mọ́lẹ̀ ní Oslo.
Àwọn model tó bá Pydantic AI mu
Id kọ̀ọ̀kan nísàlẹ̀ bá ohun tí Pydantic AI nílò mu. Èyí àkọ́kọ́ ni a ń lò ní ìbẹ̀rẹ̀ nínú àwọn àpẹẹrẹ code.
| Id model | Context window | Output tó pọ̀ jù | Input àwòrán |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | Bẹ́ẹ̀ni |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | Bẹ́ẹ̀ni |
shannon-3 | 196,608 | 65,536 | Bẹ́ẹ̀ni |
shannon-coder-1 | 131,072 | 65,536 | Rárá |
Ó dára láti mọ̀
- Lo
OpenAIChatModelfún endpoint Chat Completions ti Shannon;OpenAIResponsesModelń lo/v1/responses, èyí tí Shannon náà ń sìn láìfi àwọn èsì pamọ́. - Tool call kan ń náni ní ìbéèrè méjì: ọ̀kan tó ń béèrè fún tool náà, ọ̀kan tó ń kọ èsì láti inú abajade rẹ̀.
Àwọn ìmọ̀ràn
output_type=pẹ̀lú model Pydantic ń jẹ́ kí agent dá dátà onírú tí a ti fìdí rẹ̀ múlẹ̀ padà.OpenAIProvidernáà ń kaOPENAI_BASE_URLàtiOPENAI_API_KEYláti inú environment.agent.run_syncni ìpè tó rọrùn jù nínú àwọn script;run_streamń ṣe streaming ọ̀rọ̀ nínú koodu async.
Ìyanjú ìṣòro
| Àmì àìsàn | Ohun tó fà á | Ojútùú |
|---|---|---|
404 Not Found | base_url kò ní /v1. | Lo https://api.shannon-ai.com/v1. |
ModuleNotFoundError: openai | A fi package slim sílẹ̀ láìsí OpenAI extra. | Fi pydantic-ai-slim[openai] sílẹ̀. |
401 Unauthorized | Key náà kò sí, a tẹ̀ ẹ́ ní àṣìṣe, tàbí a ti pààrọ̀ rẹ̀. | Daakọ key náà padà láti Àwọn key àti ìlò; ó bẹ̀rẹ̀ pẹ̀lú sk-. |
context_length_exceeded tàbí ìfiránṣẹ́ "prompt is too long" | Ìjíròrò náà gùn ju context window ti model lọ. | Bẹ̀rẹ̀ chat tuntun, jẹ́ kí tool náà kó o pọ̀, tàbí yan model tí window rẹ̀ tóbi jù. |
insufficient_quota | Balance rẹ kò tó láti sanwó fún ìbéèrè náà. | Fi credit kún un tàbí yí plan padà; ìbéèrè náà kò ní tún ara rẹ̀ gbìyànjú fúnra rẹ̀. |
Àwọn ìbéèrè
Ṣé Pydantic AI ń ṣiṣẹ́ pẹ̀lú Shannon?
Bẹ́ẹ̀ ni, nípasẹ̀ OpenAIChatModel àti OpenAIProvider(base_url="https://api.shannon-ai.com/v1").
Ṣé àwọn output onírú ń ṣiṣẹ́?
Bẹ́ẹ̀ ni; Pydantic AI ń gbà wọ́n nípasẹ̀ tool call, èyí tí àwọn model Shannon ń ṣe.