ប្រើ Mastra ជាមួយ Shannon
ឱ្យ agent របស់ Mastra នូវ object ម៉ូដែលដែលមាន URL, key និង id របស់ Shannon៖ streaming និង tool បន្ទាប់មកដំណើរការលើម៉ូដែល Shannon។
- បានសាកល្បង 7 វិច្ឆិកា 2026
- OpenAI Chat Completions
- ប្រហែល 3 នាទី
អំពី Mastra
Mastra គឺជា framework TypeScript សម្រាប់ agent, workflow, សតិ និងការទាញយក ជាមួយ dev studio ក្នុងម៉ាស៊ីន។ Agent ទទួលម៉ូដែលតាមរយៈ model router របស់វា ដែលទទួល endpoint ណាក៏ដោយដែលត្រូវគ្នានឹង OpenAI ដោយផ្តល់ URL និង key។ នោះអនុញ្ញាតឱ្យ agent និង workflow របស់ Mastra ដំណើរការលើម៉ូដែល Shannon។
អ្វីដែលអ្នកត្រូវការ
- API key របស់ Shannon
- ទំព័រ Keys & usage
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - ឧទាហរណ៍កូដទាំងអស់ខាងក្រោមធ្វើតាមជម្រើសរបស់អ្នក។
រៀបចំ
-
ដំឡើង Mastra
Shellnpm install @mastra/core zod -
បង្កើត agent លើ Shannon
idគឺ<any prefix>/<Shannon id>៖urlគឺ base URL មិនមែន chat endpoint ទេ។TypeScriptimport { Agent } from "@mastra/core/agent"; import { createTool } from "@mastra/core/tools"; import { z } from "zod"; const getWeather = createTool({ id: "get-weather", description: "Weather for a city", inputSchema: z.object({ city: z.string() }), execute: async ({ city }) => ({ weather: `Sunny, 18 C in ${city}` }), }); export const agent = new Agent({ id: "assistant", name: "assistant", instructions: "Answer briefly. Use tools for weather.", model: { id: "shannon/Kimi-K3-uncensored-NVFP4", url: "https://api.shannon-ai.com/v1", apiKey: process.env.SHANNON_API_KEY }, tools: { getWeather }, }); -
Stream និងបង្កើត
TypeScriptconst stream = await agent.stream("Name three colours a cat can be."); for await (const text of stream.textStream) process.stdout.write(text); const r = await agent.generate("What is the weather in Oslo?"); console.log(r.text);
ពិនិត្យថាវាដំណើរការ
ផ្ញើ: ដំណើរការគំរូដោយកំណត់ SHANNON_API_KEY។
អ្នកគួរតែឃើញ: ពណ៌ stream មកដល់ បន្ទាប់មកចម្លើយដែលប្រើអាកាសធាតុពី tool។
ម៉ូដែលដែលសមនឹង Mastra
id នីមួយៗខាងក្រោមបំពេញតម្រូវការរបស់ Mastra។ id ទីមួយជាលំនាំដើមក្នុងឧទាហរណ៍កូដ។
| id ម៉ូដែល | បង្អួចបរិបទ | 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 | គ្មាន |
គួរដឹង
urlត្រូវតែជា base URL ដែលបញ្ចប់ដោយ/v1៖ Mastra បន្ថែម/chat/completions។- បន្ថែម
api: "responses"ទៅ object ម៉ូដែល ដើម្បីប្រើ/v1/responsesរបស់ Shannon វិញ។
គន្លឹះ
- ចុះឈ្មោះ agent ក្នុង instance
Mastraដើម្បីមើលវាក្នុង studio ក្នុងម៉ាស៊ីន (mastra dev)។ - object ម៉ូដែលដូចគ្នាដំណើរការក្នុង workflow និង memory processor ដែលទទួលម៉ូដែល។
- ដាក់ key ក្នុង
apiKeyឧទាហរណ៍ពីSHANNON_API_KEY៖ ឯកសាររបស់ Mastra មិនបានដាក់ឈ្មោះអថេរណាដែលវាអានដោយខ្លួនឯងសម្រាប់ endpoint ផ្ទាល់ខ្លួនទេ។
ការដោះស្រាយបញ្ហា
| រោគសញ្ញា | មូលហេតុ | ដំណោះស្រាយ |
|---|---|---|
404 Not Found | url ខ្វះ /v1 ឬបញ្ចប់ដោយ /chat/completions។ | ប្រើ https://api.shannon-ai.com/v1។ |
401 | apiKey ទទេ។ | ដាក់ key ក្នុង apiKey។ |
401 Unauthorized | key បាត់ វាយខុស ឬត្រូវបានប្តូរ។ | ចម្លង key ម្តងទៀតពីទំព័រ Keys & usage។ វាចាប់ផ្តើមដោយ sk-។ |
context_length_exceeded / “prompt is too long” (សំណើវែងពេក) | ការសន្ទនាវែងជាង context window របស់ម៉ូដែល។ | ចាប់ផ្តើមការជជែកថ្មី ឱ្យ tool បង្រួមវា ឬជ្រើសរើសម៉ូដែលដែលមាន window ធំជាង។ |
insufficient_quota | សមតុល្យរបស់អ្នកមិនគ្រប់គ្រាន់សម្រាប់ request ទេ។ | បញ្ចូលឥណទាន ឬប្តូរគម្រោង។ request មិនត្រូវបានព្យាយាមម្តងទៀតដោយស្វ័យប្រវត្តិទេ។ |
សំណួរ
តើ Mastra ដំណើរការជាមួយ Shannon ទេ?
បាទ/ចាស៖ ម៉ូដែល agent { id, url, apiKey } ជាមួយ url: "https://api.shannon-ai.com/v1" ទៅដល់ Shannon។
តើ tool របស់ Mastra ដំណើរការទេ?
បាទ/ចាស៖ tool ពី createTool ត្រូវបានផ្ញើជាការហៅ tool ដើម។