kobold_chat
Generate text responses using KoboldAI's chat completion capabilities through an OpenAI-compatible API interface for conversational AI applications.
Instructions
Chat completion (OpenAI-compatible)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiUrl | No | http://localhost:5001 | |
| messages | Yes | ||
| temperature | No | ||
| top_p | No | ||
| max_tokens | No | ||
| stop | No |
Implementation Reference
- src/index.ts:278-305 (handler)Implementation of the kobold_chat tool handler: appends incoming messages to in-memory chat history, sends full history to KoboldAI /v1/chat/completions endpoint (overriding with full history), adds response to history, and returns the API response as text.if (name === 'kobold_chat') { // Add new messages to chat history const newMessages = (requestData as any).messages || []; chatHistory.push(...newMessages); // Get last 4 messages const recentMessages = chatHistory.slice(-4); console.error('Last 4 messages in chat:'); console.error(JSON.stringify(recentMessages, null, 2)); // Make the API request with all context const result = await makeRequest( `${apiUrl}/v1/chat/completions`, 'POST', { ...requestData, messages: chatHistory } ); // Add assistant's response to history const typedResult = result as any; if (typedResult.choices?.[0]?.message) { chatHistory.push(typedResult.choices[0].message); } return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], isError: false, }; }
- src/index.ts:102-111 (schema)Zod input schema for kobold_chat tool: OpenAI-compatible chat completion parameters including messages array and optional sampling params.const ChatCompletionSchema = BaseConfigSchema.extend({ messages: z.array(z.object({ role: z.enum(['system', 'user', 'assistant']), content: z.string(), })), temperature: z.number().optional(), top_p: z.number().optional(), max_tokens: z.number().optional(), stop: z.array(z.string()).optional(), });
- src/index.ts:260-264 (registration)Registration of the kobold_chat tool in the ListTools response, referencing its schema.{ name: "kobold_chat", description: "Chat completion (OpenAI-compatible)", inputSchema: zodToJsonSchema(ChatCompletionSchema), },
- src/index.ts:37-41 (helper)Global in-memory chat history array used exclusively by the kobold_chat handler to maintain conversation context.const chatHistory: Array<{ role: 'system' | 'user' | 'assistant', content: string }> = []; // Generate check schemas