Sebelisa Instructor le Shannon
Hlophisa OpenAI client e supang ho Shannon ka Instructor 'me u fumane lintho tsa Pydantic ho tsoa ho li-model tsa Shannon, ka botlalo kapa ka stream.
- E lekiloe 2026 Pun 7
- OpenAI Chat Completions
- Metsotso e ka bang 1
Mabapi le Instructor
Instructor e fetola likarabo tsa model hore e be lintho tse netefalitsoeng tsa Pydantic: u fetisa response_model 'me u fumane data e nang le mofuta, ka ho leka hape ha netefatso e hloleha. E phuthela OpenAI client, kahoo ho supa client eo ho Shannon ho fana ka structured output ho tsoa ho li-model tsa Shannon.
Seo u se hlokang
- Senotlolo sa API sa Shannon
- Linotlolo le tšebeliso
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Snippet e 'ngoe le e 'ngoe e ka tlase e latela khetho ea hau.
E hlophise
-
Kenya Instructor
Shellpip install instructor openai -
Fumana ntho e nang le mofuta
Mode.TOOLSe kopa ntho ka tool call, e tšehetsoang ke li-model tsa Shannon.Pythonimport instructor from openai import OpenAI from pydantic import BaseModel client = instructor.from_openai( OpenAI(base_url="https://api.shannon-ai.com/v1", api_key="YOUR_API_KEY"), mode=instructor.Mode.TOOLS, ) class Cat(BaseModel): name: str colour: str age_years: int cat = client.chat.completions.create( model="Kimi-K3-uncensored-NVFP4", response_model=Cat, messages=[{"role": "user", "content": "Tom is a grey cat, 4 years old."}], ) print(cat) # name='Tom' colour='grey' age_years=4 -
Etsa stream ea ntho e sa fellang
Pythonfor partial in client.chat.completions.create_partial( model="Kimi-K3-uncensored-NVFP4", response_model=Cat, messages=[{"role": "user", "content": "Make up a cat: name, colour, age in years."}], ): print(partial)
Hlahloba hore e a sebetsa
Romela: Tsamaisa sampole ea pele.
U lokela ho bona: name='Tom' colour='grey' age_years=4
Li-model tse loketseng Instructor
Id e 'ngoe le e 'ngoe e ka tlase e khotsofatsa seo Instructor e se hlokang. Ea pele ke default ho li-snippet.
| Id ea model | Fensetere ea context | Tsoa e kholo ka ho fetisisa | Kenyo ea setšoantšo |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | E |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | E |
shannon-3 | 196,608 | 65,536 | E |
shannon-coder-1 | 131,072 | 65,536 | Che |
Ho molemo ho tseba
Mode.TOOLSke mokhoa oo u lokelang ho o sebelisa le Shannon; o itšetlehile ka tool calls, tseo li-model tsohle tse picker li li etsang.- Phuthela client ea hau ka
from_openaijoalo ka ha ho bontšitsoe, hore base URL le senotlolo e be tsa Shannon.
Malebela
max_retries=2hocreatee botsa model hape ha netefatso e hloleha, ka theko ea kopo e le 'ngoe ka leka-leka le leng le le leng.create_iterablee khutlisa lethathamo la lintho ho tsoa karabong e le 'ngoe, mohlala katse e 'ngoe le e 'ngoe serapeng.- Instructor e boetse e phuthela Anthropic client (
instructor.from_anthropic), eo e ka e supang ho Shannon kabase_url="https://api.shannon-ai.com"; re lekile tsela ea OpenAI.
Ho rarolla mathata
| Matšoao | Lebaka | Tokiso |
|---|---|---|
InstructorRetryException | Karabo ha ea netefala ka mor'a ho leka hape. | Nolofatsa mefuta ea masimo a model kapa u phahamise max_retries. |
404 Not Found | base_url ha e na /v1. | Sebelisa https://api.shannon-ai.com/v1. |
401 Unauthorized | Senotlolo ha se eo, se ngotsoe hampe kapa se fetotsoe. | Kopitsa senotlolo hape ho tsoa ho Keys & usage; se qala ka sk-. |
context_length_exceeded / “prompt is too long” | Puisano e telele ho feta window ea model. | Qala chat e ncha, tlohela tool e e compact, kapa khetha model e nang le window e kholoanyane. |
insufficient_quota | Balance ea hau e ke ke ea lefella kopo. | Eketsa credit kapa fetola plan; kopo ha e lekoe hape ka boeona. |
Lipotso
Na Instructor e sebetsa le Shannon?
E: phuthela OpenAI(base_url="https://api.shannon-ai.com/v1") ka instructor.from_openai.
Na streaming e a sebetsa?
E; create_partial e hlahisa ntho ha e ntse e tlatsoa, re e lekile.