@tryhamster/gerbil 1.1.3 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{architectures-wan0swXu.mjs → architectures-Ol7yUmKf.mjs} +128 -68
- package/dist/architectures-Ol7yUmKf.mjs.map +1 -0
- package/dist/cli.mjs +8 -8
- package/dist/cli.mjs.map +1 -1
- package/dist/{defaults-9komdrbY.mjs → defaults-bJcmOaRG.mjs} +2 -2
- package/dist/defaults-bJcmOaRG.mjs.map +1 -0
- package/dist/frameworks/express.mjs +1 -1
- package/dist/frameworks/fastify.mjs +1 -1
- package/dist/frameworks/hono.mjs +1 -1
- package/dist/frameworks/next.d.mts +2 -2
- package/dist/frameworks/next.mjs +1 -1
- package/dist/frameworks/trpc.mjs +1 -1
- package/dist/gerbil-0M50i8TK.mjs +4 -0
- package/dist/{gerbil-CQspp8fS.mjs → gerbil-DW1VioGN.mjs} +2 -2
- package/dist/{gerbil-CQspp8fS.mjs.map → gerbil-DW1VioGN.mjs.map} +1 -1
- package/dist/{gerbil-DZbWbIm2.d.mts → gerbil-DkilSf1Q.d.mts} +2 -2
- package/dist/{gerbil-DZbWbIm2.d.mts.map → gerbil-DkilSf1Q.d.mts.map} +1 -1
- package/dist/gpu/hooks.d.mts +24 -7
- package/dist/gpu/hooks.d.mts.map +1 -1
- package/dist/gpu/hooks.mjs +14 -7
- package/dist/gpu/hooks.mjs.map +1 -1
- package/dist/gpu/index.d.mts +2 -2
- package/dist/gpu/index.mjs +5 -5
- package/dist/{gpu-BYCQ5aTI.mjs → gpu-DR6EG0K-.mjs} +93 -24
- package/dist/gpu-DR6EG0K-.mjs.map +1 -0
- package/dist/index-Dgmb2kE3.d.mts.map +1 -1
- package/dist/{index-CKszv3lt.d.mts → index-HVS7yeLx.d.mts} +232 -133
- package/dist/index-HVS7yeLx.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +6 -6
- package/dist/integrations/ai-sdk.mjs +1 -1
- package/dist/integrations/langchain.mjs +1 -1
- package/dist/integrations/llamaindex.mjs +1 -1
- package/dist/integrations/mcp.d.mts +2 -2
- package/dist/integrations/mcp.mjs +4 -4
- package/dist/{mcp-CszII8GJ.mjs → mcp-8Tn3U-EE.mjs} +3 -3
- package/dist/{mcp-CszII8GJ.mjs.map → mcp-8Tn3U-EE.mjs.map} +1 -1
- package/dist/moonshine-stt-B3YtKcEE.mjs +4 -0
- package/dist/{moonshine-stt-DDUm5WfP.mjs → moonshine-stt-DSz3VW_0.mjs} +56 -6
- package/dist/{moonshine-stt-DDUm5WfP.mjs.map → moonshine-stt-DSz3VW_0.mjs.map} +1 -1
- package/dist/{one-liner-DVche8Eg.mjs → one-liner-BK9wqRYw.mjs} +2 -2
- package/dist/{one-liner-DVche8Eg.mjs.map → one-liner-BK9wqRYw.mjs.map} +1 -1
- package/dist/repl-B62rx3DS.mjs +9 -0
- package/dist/skills/index.d.mts +2 -2
- package/dist/skills/index.mjs +3 -3
- package/dist/{skills-BQI-VSn2.mjs → skills-BF3FVv8_.mjs} +2 -2
- package/dist/{skills-BQI-VSn2.mjs.map → skills-BF3FVv8_.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/architectures-wan0swXu.mjs.map +0 -1
- package/dist/defaults-9komdrbY.mjs.map +0 -1
- package/dist/gerbil-tHnYb9nZ.mjs +0 -4
- package/dist/gpu-BYCQ5aTI.mjs.map +0 -1
- package/dist/index-CKszv3lt.d.mts.map +0 -1
- package/dist/moonshine-stt-BtR-KiSP.mjs +0 -4
- package/dist/repl-BYJA2U7t.mjs +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-CszII8GJ.mjs","names":["handlers: Record<string, (args: any) => Promise<any>>","skills.summarize","skills.explain","skills.review","skills.commit","skills.translate"],"sources":["../src/integrations/mcp.ts"],"sourcesContent":["/**\n * Gerbil MCP Server\n *\n * Model Context Protocol server for Claude Desktop, Cursor, etc.\n *\n * @example\n * ```bash\n * gerbil serve --mcp\n * ```\n *\n * @example Claude Desktop config\n * ```json\n * {\n * \"mcpServers\": {\n * \"gerbil\": {\n * \"command\": \"npx\",\n * \"args\": [\"-y\", \"gerbil\", \"serve\", \"--mcp\"]\n * }\n * }\n * }\n * ```\n */\n\nimport { Gerbil } from \"../core/gerbil.js\";\nimport { DEFAULT_MODEL } from \"../core/models.js\";\nimport type { GerbilConfig } from \"../core/types.js\";\nimport * as skills from \"../skills/index.js\";\n\nexport interface MCPServerOptions extends GerbilConfig {\n /** Port for HTTP transport (default: stdio) */\n port?: number;\n\n /** Tools to expose */\n tools?: string[];\n}\n\n// Tool definitions\nconst TOOL_DEFINITIONS = {\n generate: {\n name: \"gerbil_generate\",\n description: \"Generate text using a local LLM\",\n inputSchema: {\n type: \"object\",\n properties: {\n prompt: { type: \"string\", description: \"The prompt to generate from\" },\n maxTokens: { type: \"number\", description: \"Maximum tokens to generate\" },\n temperature: { type: \"number\", description: \"Sampling temperature (0-2)\" },\n system: { type: \"string\", description: \"System prompt\" },\n thinking: { type: \"boolean\", description: \"Enable thinking mode\" },\n },\n required: [\"prompt\"],\n },\n },\n summarize: {\n name: \"gerbil_summarize\",\n description: \"Summarize content\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Content to summarize\" },\n length: { type: \"string\", enum: [\"short\", \"medium\", \"long\"] },\n format: { type: \"string\", enum: [\"paragraph\", \"bullets\"] },\n },\n required: [\"content\"],\n },\n },\n explain: {\n name: \"gerbil_explain\",\n description: \"Explain code or concepts\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Code or concept to explain\" },\n level: { type: \"string\", enum: [\"beginner\", \"intermediate\", \"expert\"] },\n language: { type: \"string\", description: \"Programming language\" },\n },\n required: [\"content\"],\n },\n },\n review: {\n name: \"gerbil_review\",\n description: \"Review code for issues\",\n inputSchema: {\n type: \"object\",\n properties: {\n code: { type: \"string\", description: \"Code to review\" },\n focus: {\n type: \"array\",\n items: { type: \"string\", enum: [\"security\", \"performance\", \"style\", \"bugs\"] },\n },\n },\n required: [\"code\"],\n },\n },\n commit: {\n name: \"gerbil_commit\",\n description: \"Generate a commit message from a diff\",\n inputSchema: {\n type: \"object\",\n properties: {\n diff: { type: \"string\", description: \"Git diff\" },\n type: { type: \"string\", enum: [\"conventional\", \"simple\", \"detailed\"] },\n },\n required: [\"diff\"],\n },\n },\n translate: {\n name: \"gerbil_translate\",\n description: \"Translate text\",\n inputSchema: {\n type: \"object\",\n properties: {\n text: { type: \"string\", description: \"Text to translate\" },\n to: { type: \"string\", description: \"Target language\" },\n from: { type: \"string\", description: \"Source language (optional)\" },\n },\n required: [\"text\", \"to\"],\n },\n },\n embed: {\n name: \"gerbil_embed\",\n description: \"Generate embeddings for text\",\n inputSchema: {\n type: \"object\",\n properties: {\n text: { type: \"string\", description: \"Text to embed\" },\n },\n required: [\"text\"],\n },\n },\n};\n\n/**\n * Create MCP server\n */\nexport async function createMCPServer(options: MCPServerOptions = {}) {\n const g = new Gerbil(options);\n\n // Load model\n await g.loadModel(options.model || DEFAULT_MODEL);\n\n // Determine which tools to expose\n const enabledTools = options.tools || Object.keys(TOOL_DEFINITIONS);\n\n // Tool handlers\n const handlers: Record<string, (args: any) => Promise<any>> = {\n gerbil_generate: async (args) => {\n const result = await g.generate(args.prompt, {\n maxTokens: args.maxTokens,\n temperature: args.temperature,\n system: args.system,\n thinking: args.thinking,\n });\n return {\n content: [\n {\n type: \"text\",\n text: result.thinking\n ? `Thinking: ${result.thinking}\\n\\nAnswer: ${result.text}`\n : result.text,\n },\n ],\n };\n },\n\n gerbil_summarize: async (args) => {\n const summary = await skills.summarize({\n content: args.content,\n length: args.length,\n format: args.format,\n });\n return { content: [{ type: \"text\", text: summary }] };\n },\n\n gerbil_explain: async (args) => {\n const explanation = await skills.explain({\n content: args.content,\n level: args.level,\n language: args.language,\n } as Parameters<typeof skills.explain>[0]);\n return { content: [{ type: \"text\", text: explanation }] };\n },\n\n gerbil_review: async (args) => {\n const reviewResult = await skills.review({\n code: args.code,\n focus: args.focus,\n } as Parameters<typeof skills.review>[0]);\n return { content: [{ type: \"text\", text: reviewResult }] };\n },\n\n gerbil_commit: async (args) => {\n const message = await skills.commit({\n diff: args.diff,\n type: args.type,\n } as Parameters<typeof skills.commit>[0]);\n return { content: [{ type: \"text\", text: message }] };\n },\n\n gerbil_translate: async (args) => {\n const translated = await skills.translate({\n text: args.text,\n to: args.to,\n from: args.from,\n } as Parameters<typeof skills.translate>[0]);\n return { content: [{ type: \"text\", text: translated }] };\n },\n\n gerbil_embed: async (args) => {\n const result = await g.embed(args.text);\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify({\n vector: result.vector.slice(0, 10),\n dimensions: result.vector.length,\n }),\n },\n ],\n };\n },\n };\n\n return {\n // Server info\n info: {\n name: \"gerbil\",\n version: \"1.0.0\",\n description: \"Local LLM inference via Gerbil\",\n },\n\n // List available tools\n listTools: () =>\n enabledTools\n .filter((t) => TOOL_DEFINITIONS[t as keyof typeof TOOL_DEFINITIONS])\n .map((t) => TOOL_DEFINITIONS[t as keyof typeof TOOL_DEFINITIONS]),\n\n // Call a tool\n callTool: async (name: string, args: any) => {\n const handler = handlers[name];\n if (!handler) {\n throw new Error(`Unknown tool: ${name}`);\n }\n return handler(args);\n },\n\n // Get Gerbil instance\n gerbil: g,\n };\n}\n\n/**\n * Start MCP server with stdio transport\n */\nexport async function startMCPServer(options: MCPServerOptions = {}) {\n const server = await createMCPServer(options);\n\n // Simple stdio protocol handler\n const readline = await import(\"node:readline\");\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on(\"line\", async (line) => {\n try {\n const request = JSON.parse(line);\n\n let _response: any;\n\n switch (request.method) {\n case \"initialize\":\n _response = {\n protocolVersion: \"2024-11-05\",\n serverInfo: server.info,\n capabilities: {\n tools: {},\n },\n };\n break;\n\n case \"tools/list\":\n _response = { tools: server.listTools() };\n break;\n\n case \"tools/call\":\n _response = await server.callTool(request.params.name, request.params.arguments);\n break;\n\n default:\n _response = { error: { code: -32_601, message: \"Method not found\" } };\n }\n } catch (_error) {}\n });\n}\n\nexport default { createMCPServer, startMCPServer };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAM,mBAAmB;CACvB,UAAU;EACR,MAAM;EACN,aAAa;EACb,aAAa;GACX,MAAM;GACN,YAAY;IACV,QAAQ;KAAE,MAAM;KAAU,aAAa;KAA+B;IACtE,WAAW;KAAE,MAAM;KAAU,aAAa;KAA8B;IACxE,aAAa;KAAE,MAAM;KAAU,aAAa;KAA8B;IAC1E,QAAQ;KAAE,MAAM;KAAU,aAAa;KAAiB;IACxD,UAAU;KAAE,MAAM;KAAW,aAAa;KAAwB;IACnE;GACD,UAAU,CAAC,SAAS;GACrB;EACF;CACD,WAAW;EACT,MAAM;EACN,aAAa;EACb,aAAa;GACX,MAAM;GACN,YAAY;IACV,SAAS;KAAE,MAAM;KAAU,aAAa;KAAwB;IAChE,QAAQ;KAAE,MAAM;KAAU,MAAM;MAAC;MAAS;MAAU;MAAO;KAAE;IAC7D,QAAQ;KAAE,MAAM;KAAU,MAAM,CAAC,aAAa,UAAU;KAAE;IAC3D;GACD,UAAU,CAAC,UAAU;GACtB;EACF;CACD,SAAS;EACP,MAAM;EACN,aAAa;EACb,aAAa;GACX,MAAM;GACN,YAAY;IACV,SAAS;KAAE,MAAM;KAAU,aAAa;KAA8B;IACtE,OAAO;KAAE,MAAM;KAAU,MAAM;MAAC;MAAY;MAAgB;MAAS;KAAE;IACvE,UAAU;KAAE,MAAM;KAAU,aAAa;KAAwB;IAClE;GACD,UAAU,CAAC,UAAU;GACtB;EACF;CACD,QAAQ;EACN,MAAM;EACN,aAAa;EACb,aAAa;GACX,MAAM;GACN,YAAY;IACV,MAAM;KAAE,MAAM;KAAU,aAAa;KAAkB;IACvD,OAAO;KACL,MAAM;KACN,OAAO;MAAE,MAAM;MAAU,MAAM;OAAC;OA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S;AACzB,OAAI,CAAC,QACH,OAAM,IAAI,MAAM,iBAAiB,OAAO;AAE1C,UAAO,QAAQ,KAAK;;EAItB,QAAQ;EACT;;;;;AAMH,eAAsB,eAAe,UAA4B,EAAE,EAAE;CACnE,MAAM,SAAS,MAAM,gBAAgB,QAAQ;AAU7C,EAPiB,MAAM,OAAO,kBACV,gBAAgB;EAClC,OAAO,QAAQ;EACf,QAAQ,QAAQ;EAChB,UAAU;EACX,CAAC,CAEC,GAAG,QAAQ,OAAO,SAAS;AAC5B,MAAI;GACF,MAAM,UAAU,KAAK,MAAM,KAAK;AAIhC,WAAQ,QAAQ,QAAhB;IACE,KAAK;AACH,KAEc,OAAO;AAKrB;IAEF,KAAK;AACH,KAAqB,OAAO,WAAW;AACvC;IAEF,KAAK;AACH,KAAY,MAAM,OAAO,SAAS,QAAQ,OAAO,MAAM,QAAQ,OAAO,UAAU;AAChF;IAEF;;WAGK,QAAQ;GACjB;;AAGJ,kBAAe;CAAE;CAAiB;CAAgB"}
|
|
1
|
+
{"version":3,"file":"mcp-8Tn3U-EE.mjs","names":["handlers: Record<string, (args: any) => Promise<any>>","skills.summarize","skills.explain","skills.review","skills.commit","skills.translate"],"sources":["../src/integrations/mcp.ts"],"sourcesContent":["/**\n * Gerbil MCP Server\n *\n * Model Context Protocol server for Claude Desktop, Cursor, etc.\n *\n * @example\n * ```bash\n * gerbil serve --mcp\n * ```\n *\n * @example Claude Desktop config\n * ```json\n * {\n * \"mcpServers\": {\n * \"gerbil\": {\n * \"command\": \"npx\",\n * \"args\": [\"-y\", \"gerbil\", \"serve\", \"--mcp\"]\n * }\n * }\n * }\n * ```\n */\n\nimport { Gerbil } from \"../core/gerbil.js\";\nimport { DEFAULT_MODEL } from \"../core/models.js\";\nimport type { GerbilConfig } from \"../core/types.js\";\nimport * as skills from \"../skills/index.js\";\n\nexport interface MCPServerOptions extends GerbilConfig {\n /** Port for HTTP transport (default: stdio) */\n port?: number;\n\n /** Tools to expose */\n tools?: string[];\n}\n\n// Tool definitions\nconst TOOL_DEFINITIONS = {\n generate: {\n name: \"gerbil_generate\",\n description: \"Generate text using a local LLM\",\n inputSchema: {\n type: \"object\",\n properties: {\n prompt: { type: \"string\", description: \"The prompt to generate from\" },\n maxTokens: { type: \"number\", description: \"Maximum tokens to generate\" },\n temperature: { type: \"number\", description: \"Sampling temperature (0-2)\" },\n system: { type: \"string\", description: \"System prompt\" },\n thinking: { type: \"boolean\", description: \"Enable thinking mode\" },\n },\n required: [\"prompt\"],\n },\n },\n summarize: {\n name: \"gerbil_summarize\",\n description: \"Summarize content\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Content to summarize\" },\n length: { type: \"string\", enum: [\"short\", \"medium\", \"long\"] },\n format: { type: \"string\", enum: [\"paragraph\", \"bullets\"] },\n },\n required: [\"content\"],\n },\n },\n explain: {\n name: \"gerbil_explain\",\n description: \"Explain code or concepts\",\n inputSchema: {\n type: \"object\",\n properties: {\n content: { type: \"string\", description: \"Code or concept to explain\" },\n level: { type: \"string\", enum: [\"beginner\", \"intermediate\", \"expert\"] },\n language: { type: \"string\", description: \"Programming language\" },\n },\n required: [\"content\"],\n },\n },\n review: {\n name: \"gerbil_review\",\n description: \"Review code for issues\",\n inputSchema: {\n type: \"object\",\n properties: {\n code: { type: \"string\", description: \"Code to review\" },\n focus: {\n type: \"array\",\n items: { type: \"string\", enum: [\"security\", \"performance\", \"style\", \"bugs\"] },\n },\n },\n required: [\"code\"],\n },\n },\n commit: {\n name: \"gerbil_commit\",\n description: \"Generate a commit message from a diff\",\n inputSchema: {\n type: \"object\",\n properties: {\n diff: { type: \"string\", description: \"Git diff\" },\n type: { type: \"string\", enum: [\"conventional\", \"simple\", \"detailed\"] },\n },\n required: [\"diff\"],\n },\n },\n translate: {\n name: \"gerbil_translate\",\n description: \"Translate text\",\n inputSchema: {\n type: \"object\",\n properties: {\n text: { type: \"string\", description: \"Text to translate\" },\n to: { type: \"string\", description: \"Target language\" },\n from: { type: \"string\", description: \"Source language (optional)\" },\n },\n required: [\"text\", \"to\"],\n },\n },\n embed: {\n name: \"gerbil_embed\",\n description: \"Generate embeddings for text\",\n inputSchema: {\n type: \"object\",\n properties: {\n text: { type: \"string\", description: \"Text to embed\" },\n },\n required: [\"text\"],\n },\n },\n};\n\n/**\n * Create MCP server\n */\nexport async function createMCPServer(options: MCPServerOptions = {}) {\n const g = new Gerbil(options);\n\n // Load model\n await g.loadModel(options.model || DEFAULT_MODEL);\n\n // Determine which tools to expose\n const enabledTools = options.tools || Object.keys(TOOL_DEFINITIONS);\n\n // Tool handlers\n const handlers: Record<string, (args: any) => Promise<any>> = {\n gerbil_generate: async (args) => {\n const result = await g.generate(args.prompt, {\n maxTokens: args.maxTokens,\n temperature: args.temperature,\n system: args.system,\n thinking: args.thinking,\n });\n return {\n content: [\n {\n type: \"text\",\n text: result.thinking\n ? `Thinking: ${result.thinking}\\n\\nAnswer: ${result.text}`\n : result.text,\n },\n ],\n };\n },\n\n gerbil_summarize: async (args) => {\n const summary = await skills.summarize({\n content: args.content,\n length: args.length,\n format: args.format,\n });\n return { content: [{ type: \"text\", text: summary }] };\n },\n\n gerbil_explain: async (args) => {\n const explanation = await skills.explain({\n content: args.content,\n level: args.level,\n language: args.language,\n } as Parameters<typeof skills.explain>[0]);\n return { content: [{ type: \"text\", text: explanation }] };\n },\n\n gerbil_review: async (args) => {\n const reviewResult = await skills.review({\n code: args.code,\n focus: args.focus,\n } as Parameters<typeof skills.review>[0]);\n return { content: [{ type: \"text\", text: reviewResult }] };\n },\n\n gerbil_commit: async (args) => {\n const message = await skills.commit({\n diff: args.diff,\n type: args.type,\n } as Parameters<typeof skills.commit>[0]);\n return { content: [{ type: \"text\", text: message }] };\n },\n\n gerbil_translate: async (args) => {\n const translated = await skills.translate({\n text: args.text,\n to: args.to,\n from: args.from,\n } as Parameters<typeof skills.translate>[0]);\n return { content: [{ type: \"text\", text: translated }] };\n },\n\n gerbil_embed: async (args) => {\n const result = await g.embed(args.text);\n return {\n content: [\n {\n type: \"text\",\n text: JSON.stringify({\n vector: result.vector.slice(0, 10),\n dimensions: result.vector.length,\n }),\n },\n ],\n };\n },\n };\n\n return {\n // Server info\n info: {\n name: \"gerbil\",\n version: \"1.0.0\",\n description: \"Local LLM inference via Gerbil\",\n },\n\n // List available tools\n listTools: () =>\n enabledTools\n .filter((t) => TOOL_DEFINITIONS[t as keyof typeof TOOL_DEFINITIONS])\n .map((t) => TOOL_DEFINITIONS[t as keyof typeof TOOL_DEFINITIONS]),\n\n // Call a tool\n callTool: async (name: string, args: any) => {\n const handler = handlers[name];\n if (!handler) {\n throw new Error(`Unknown tool: ${name}`);\n }\n return handler(args);\n },\n\n // Get Gerbil instance\n gerbil: g,\n };\n}\n\n/**\n * Start MCP server with stdio transport\n */\nexport async function startMCPServer(options: MCPServerOptions = {}) {\n const server = await createMCPServer(options);\n\n // Simple stdio protocol handler\n const readline = await import(\"node:readline\");\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n terminal: false,\n });\n\n rl.on(\"line\", async (line) => {\n try {\n const request = JSON.parse(line);\n\n let _response: any;\n\n switch (request.method) {\n case \"initialize\":\n _response = {\n protocolVersion: \"2024-11-05\",\n serverInfo: server.info,\n capabilities: {\n tools: {},\n },\n };\n break;\n\n case \"tools/list\":\n _response = { tools: server.listTools() };\n break;\n\n case \"tools/call\":\n _response = await server.callTool(request.params.name, request.params.arguments);\n break;\n\n default:\n _response = { error: { code: -32_601, message: \"Method not found\" } };\n }\n } catch (_error) {}\n });\n}\n\nexport default { createMCPServer, startMCPServer };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAM,mBAAmB;CACvB,UAAU;EACR,MAAM;EACN,aAAa;EACb,aAAa;GACX,MAAM;GACN,YAAY;IACV,QAAQ;KAAE,MAAM;KAAU,aAAa;KAA+B;IACtE,WAAW;KAAE,MAAM;KAAU,aAAa;KAA8B;IACxE,aAAa;KAAE,MAAM;KAAU,aAAa;KAA8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AAhB;IACE,KAAK;AACH,KAEc,OAAO;AAKrB;IAEF,KAAK;AACH,KAAqB,OAAO,WAAW;AACvC;IAEF,KAAK;AACH,KAAY,MAAM,OAAO,SAAS,QAAQ,OAAO,MAAM,QAAQ,OAAO,UAAU;AAChF;IAEF;;WAGK,QAAQ;GACjB;;AAGJ,kBAAe;CAAE;CAAiB;CAAgB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as createDefaultHFKeyMapper, S as
|
|
1
|
+
import { C as quantizeInt4, D as createDefaultHFKeyMapper, S as DEFAULT_GROUP_SIZE, T as DTYPE_BYTES, a as generateMoonshineEncoderGraph, b as nanoCodecWeightMap, i as generateMoonshineDecoderGraph, o as moonshineEncoderFrames, p as foldNanoCodecWeightNorm, s as parseMoonshineConfig, t as generateGraph, w as CANONICAL_KEYS } from "./architectures-Ol7yUmKf.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/gpu/device.ts
|
|
4
4
|
const COPY_SRC = 4;
|
|
@@ -11948,7 +11948,7 @@ function buildKaniCodecWeights(codecRaw) {
|
|
|
11948
11948
|
}
|
|
11949
11949
|
async function loadKaniTTS(options) {
|
|
11950
11950
|
const revision = options.revision ?? "main";
|
|
11951
|
-
const repo = options.repo ?? "nineninesix/kani-tts-2-
|
|
11951
|
+
const repo = options.repo ?? "nineninesix/kani-tts-450m-0.2-ft";
|
|
11952
11952
|
const codecRepo = options.codecRepo ?? KANI_NANOCODEC_REPO;
|
|
11953
11953
|
const baseURL = await resolveModelBaseURL(repo, revision);
|
|
11954
11954
|
const codecURL = await resolveModelBaseURL(codecRepo, "main");
|
|
@@ -11961,7 +11961,16 @@ async function loadKaniTTS(options) {
|
|
|
11961
11961
|
const backboneBuf = await fetchBinary(baseURL, "model.safetensors", options.hfToken, (loaded, total) => options.onProgress?.(8 + loaded / (total || 1) * 45, 100, "backbone weights"), options.cacheDir);
|
|
11962
11962
|
const backboneFile = parseSafetensorsHeader(backboneBuf);
|
|
11963
11963
|
const backboneWeights = /* @__PURE__ */ new Map();
|
|
11964
|
+
const preQuantized = (rawConfig.quantization ?? void 0)?.format === "gerbil-int4";
|
|
11965
|
+
const isQuantTensor = (name) => name.endsWith(".q") || name.endsWith(".scales") || name.endsWith(".zeros");
|
|
11964
11966
|
for (const entry of backboneFile.entries) {
|
|
11967
|
+
if (preQuantized && isQuantTensor(entry.name)) {
|
|
11968
|
+
backboneWeights.set(entry.name, {
|
|
11969
|
+
data: getTensorData(backboneBuf, backboneFile, entry),
|
|
11970
|
+
shape: entry.shape
|
|
11971
|
+
});
|
|
11972
|
+
continue;
|
|
11973
|
+
}
|
|
11965
11974
|
const key = (entry.name.startsWith("model.") ? entry.name.slice(6) : entry.name).replace(KANI_OUT_PROJ_RE, ".self_attn.o_proj.");
|
|
11966
11975
|
backboneWeights.set(key, {
|
|
11967
11976
|
data: toF32(entry, backboneBuf, backboneFile),
|
|
@@ -11978,14 +11987,55 @@ async function loadKaniTTS(options) {
|
|
|
11978
11987
|
shape: entry.shape
|
|
11979
11988
|
});
|
|
11980
11989
|
const codecWeights = buildKaniCodecWeights(codecRaw);
|
|
11981
|
-
options.onProgress?.(100, 100, "Kani-TTS
|
|
11990
|
+
options.onProgress?.(100, 100, "Kani-TTS loaded.");
|
|
11982
11991
|
return {
|
|
11983
11992
|
backboneWeights,
|
|
11984
11993
|
codecWeights,
|
|
11985
11994
|
tokenizer,
|
|
11986
|
-
rawConfig
|
|
11995
|
+
rawConfig,
|
|
11996
|
+
preQuantized
|
|
11987
11997
|
};
|
|
11988
11998
|
}
|
|
11999
|
+
/**
|
|
12000
|
+
* Quantize the Kani codec-LM backbone's linear weights to INT4 in place.
|
|
12001
|
+
*
|
|
12002
|
+
* Walks the built backbone graph's `MatMulInt4` nodes (the q4 graph emits these for
|
|
12003
|
+
* every LFM2 linear projection — q/k/v/o, gate/up/down, short-conv in/out_proj) and,
|
|
12004
|
+
* for each, quantizes the f32 source weight (group-wise W4A16 via `quantizeInt4`)
|
|
12005
|
+
* into the `.q`/`.scales`/`.zeros` entries the executor binds, then frees the f32
|
|
12006
|
+
* source to release memory. Mirrors the main loader's q4 loop, but operates on the
|
|
12007
|
+
* dedicated Kani backbone weight map (which the loader builds at f32). The tied
|
|
12008
|
+
* embedding + LM head are intentionally NOT quantized (the graph keeps them f32),
|
|
12009
|
+
* so this leaves `embed_tokens.weight` untouched. Idempotent: tensors already
|
|
12010
|
+
* present (`.q` set) are skipped.
|
|
12011
|
+
*/
|
|
12012
|
+
function quantizeKaniBackbone(graph, weights) {
|
|
12013
|
+
for (const node of graph.nodes) {
|
|
12014
|
+
if (node.opType !== "MatMulInt4") continue;
|
|
12015
|
+
const groupSz = node.attributes.group_size ?? DEFAULT_GROUP_SIZE;
|
|
12016
|
+
const qName = node.inputs[1];
|
|
12017
|
+
const scalesName = node.inputs[2];
|
|
12018
|
+
const zerosName = node.inputs[3];
|
|
12019
|
+
if (weights.has(qName)) continue;
|
|
12020
|
+
const sourceName = qName.slice(0, -2);
|
|
12021
|
+
const source = weights.get(sourceName);
|
|
12022
|
+
if (!source) continue;
|
|
12023
|
+
const { packed, scales, zeros } = quantizeInt4(source.data instanceof Float32Array ? source.data : new Float32Array(source.data.buffer, source.data.byteOffset, source.data.byteLength / 4), groupSz);
|
|
12024
|
+
weights.set(qName, {
|
|
12025
|
+
data: packed,
|
|
12026
|
+
shape: [packed.length]
|
|
12027
|
+
});
|
|
12028
|
+
weights.set(scalesName, {
|
|
12029
|
+
data: scales,
|
|
12030
|
+
shape: [scales.length]
|
|
12031
|
+
});
|
|
12032
|
+
weights.set(zerosName, {
|
|
12033
|
+
data: zeros,
|
|
12034
|
+
shape: [zeros.length]
|
|
12035
|
+
});
|
|
12036
|
+
weights.delete(sourceName);
|
|
12037
|
+
}
|
|
12038
|
+
}
|
|
11989
12039
|
|
|
11990
12040
|
//#endregion
|
|
11991
12041
|
//#region src/gpu/moonshine-executor.ts
|
|
@@ -12351,5 +12401,5 @@ function selectGraphWeights(graph, weights) {
|
|
|
12351
12401
|
}
|
|
12352
12402
|
|
|
12353
12403
|
//#endregion
|
|
12354
|
-
export {
|
|
12355
|
-
//# sourceMappingURL=moonshine-stt-
|
|
12404
|
+
export { initGPU as _, loadMoonshine as a, Executor as c, clearPipelineCache as d, createBindGroup as f, getOrCreatePipeline as g, destroyBuffers as h, loadModel as i, KERNEL_REGISTRY as l, createUniformBuffer as m, MoonshineEncoderExecutor as n, quantizeKaniBackbone as o, createStorageBuffer as p, loadKaniTTS as r, remapPrunedToken as s, MoonshineSTT as t, MATMUL_BIAS_F16C_SPEC as u, verifyGPU as v };
|
|
12405
|
+
//# sourceMappingURL=moonshine-stt-DSz3VW_0.mjs.map
|