ollama_generate
Generate a single-turn completion from a prompt using a specified model, with optional settings like temperature and format (json or markdown).
Instructions
Generate completion from a prompt. Simpler than chat, useful for single-turn completions.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | Name of the model to use | |
| prompt | Yes | The prompt to generate from | |
| options | No | Generation options (optional). Provide as JSON object with settings like temperature, top_p, etc. | |
| format | No | json |
Implementation Reference
- src/tools/generate.ts:56-66 (handler)Handler function for the ollama_generate tool. Validates args via GenerateInputSchema and calls generateWithModel.
handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => { const validated = GenerateInputSchema.parse(args); return generateWithModel( ollama, validated.model, validated.prompt, validated.options || {}, format ); }, }; - src/tools/generate.ts:11-27 (helper)Core function that calls ollama.generate() with the given model, prompt, options, and format. Used by the handler.
export async function generateWithModel( ollama: Ollama, model: string, prompt: string, options: GenerationOptions, format: ResponseFormat ): Promise<string> { const response = await ollama.generate({ model, prompt, options, format: format === ResponseFormat.JSON ? 'json' : undefined, stream: false, }); return formatResponse(response.response, format); } - src/schemas.ts:103-109 (schema)Zod schema for validating ollama_generate inputs: model, prompt, options, format, and stream.
export const GenerateInputSchema = z.object({ model: z.string().min(1), prompt: z.string(), options: parseJsonOrDefault({}).pipe(GenerationOptionsSchema), format: ResponseFormatSchema.default('json'), stream: z.boolean().default(false), }); - src/tools/generate.ts:29-66 (registration)ToolDefinition export with name 'ollama_generate', description, inputSchema, and handler. Auto-loaded by the discoverTools function in autoloader.ts.
export const toolDefinition: ToolDefinition = { name: 'ollama_generate', description: 'Generate completion from a prompt. Simpler than chat, useful for single-turn completions.', inputSchema: { type: 'object', properties: { model: { type: 'string', description: 'Name of the model to use', }, prompt: { type: 'string', description: 'The prompt to generate from', }, options: { type: 'string', description: 'Generation options (optional). Provide as JSON object with settings like temperature, top_p, etc.', }, format: { type: 'string', enum: ['json', 'markdown'], default: 'json', }, }, required: ['model', 'prompt'], }, handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => { const validated = GenerateInputSchema.parse(args); return generateWithModel( ollama, validated.model, validated.prompt, validated.options || {}, format ); }, };