Ampiasao amin'i Shannon ny OpenAI SDK
Tazony ny SDK OpenAI efa ampiasainao: ovay ny base URL sy ny key, ary fidio id model Shannon.
- Notsapaina tamin'ny 7 Nov 2026
- OpenAI Chat Completions
- Manodidina ny 1 min
Momba ny OpenAI SDK
Ny tranombokin'ny OpenAI ofisialy ho an'ny Python sy Node.js no fomba mahazatra indrindra hiantsoana chat API avy amin'ny code. Mandray base URL izy ireo, ka mandeha amin'i Shannon ny code mitovy: chat completions, streaming, tool call ary ny Responses API.
Izay ilainao
- API key Shannon
- Fanalahidy sy fampiasana
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Manaraka ny safidinao ny ohatra rehetra etsy ambany.
Fametrahana
-
Apetraho ny SDK
pip install openainpm install openai -
Ampitondrao any amin'i Shannon
Ny client ihany no miova. Ny SDK koa dia mamaky ny
OPENAI_BASE_URLsyOPENAI_API_KEYavy ao amin'ny environment.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 ?? ""); -
Miantso tool
Mandeha toy ny amin'ny OpenAI ny tool: mifarana amin'ny
finish_reason: "tool_calls"ny valiny ary ao amin'nymessage.tool_callsny antso.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"}
Hamarino fa miasa
Alefaso: Alefaso ny santionany streaming.
Tokony ho hitanao: Voaonta mandritra ny stream ny loko, ohatra "Cats can be black, white, and orange."
Model mifanaraka amin'ny OpenAI SDK
Mahafeno izay ilain'ny OpenAI SDK ny id rehetra etsy ambany. Ny voalohany no default ao amin'ny ohatra kaody.
| Id model | Context window | Output farany | Sary ho fidirana |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | Eny |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | Eny |
shannon-3 | 196,608 | 65,536 | Eny |
shannon-coder-1 | 131,072 | 65,536 | Tsia |
Tsara ho fantatra
- Mandeha koa ny
client.responses.create(...); Shannon dia manome/v1/responsestsy mitahiry valiny, ka alefaso ny resaka manontolo isaky ny mandefa. - Tonga ho
reasoning_contentao amin'nydeltaan'ny chunk tsirairay ny reasoning, eo anilan'nycontent. - Tsy misy
/v1/embeddings; ampiasao model embedding hafa ho an'ny retrieval.
Toro-hevitra
- Apetraho ao amin'ny environment ny
OPENAI_BASE_URLsyOPENAI_API_KEYary raisin'ny client ho azy tsy misy argument, ka tsy mila fanovana ny code efa misy. - Ampio
stream=Trueho an'ny valiny lava; tonga isaky ny soratana ny lahatsoratra sy ny reasoning. - Apetraho ao amin'ny client ny
max_retriessytimeout: ny SDK dia manandrana indray ho azy ny valiny429sy5xx. - Vakio ny
usageisaky ny valiny mba hitahirizana ny isan'ny token nampiasain'ny antso tsirairay, anisan'izany ireo voatahiry ao amin'ny cache.
Famahana olana
| Soritr'aretina | Antony | Vahaolana |
|---|---|---|
404 Not Found | Tsy misy /v1 ao amin'ny base_url. | Ampiasao ny https://api.shannon-ai.com/v1. |
400 unknown model | Anaran'ny model OpenAI toy ny gpt-4o. | Ampiasao id Shannon avy amin'ny GET /v1/models. |
401 Unauthorized | Tsy ao ny key, diso soratra, na efa novaina. | Adikao indray ny key avy ao amin'ny Keys & usage; manomboka amin'ny sk- izy. |
context_length_exceeded na "prompt is too long" | Lava noho ny context window an'ny model ny resaka. | Manombohy chat vaovao, avelao ny fitaovana hanafohy azy, na misafidiana model manana window lehibe kokoa. |
insufficient_quota | Tsy ampy handoavana ny fangatahana ny balance-nao. | Ampio ny balance na ovay ny plan; tsy averina ho azy ny fangatahana. |
Fanontaniana
Solon'ny API OpenAI tsotra ve i Shannon?
Ho an'ny chat completions, ny Responses API, streaming, tool ary structured output, eny: ovay ny base_url, ny key ary ny id model.
Mandeha koa ve ny SDK Anthropic?
Eny: miresaka amin'ny /v1/messages ny Anthropic(base_url="https://api.shannon-ai.com", api_key=...).