Skip to main content
Glama

ollama_generate

Generate single-turn text completions from prompts using local Ollama models. Provide a model name and prompt to create structured outputs in JSON or Markdown format.

Instructions

Generate completion from a prompt. Simpler than chat, useful for single-turn completions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYesName of the model to use
promptYesThe prompt to generate from
optionsNoGeneration options (optional). Provide as JSON object with settings like temperature, top_p, etc.
formatNojson

Implementation Reference

  • Core handler logic: calls ollama.generate with the provided model, prompt, options, and formats the response using formatResponse.
    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); }
  • Zod schema used for validating the input arguments in the tool handler.
    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), });
  • Tool registration: exports toolDefinition with name 'ollama_generate', description, input schema (for tool description), and handler that validates args and calls generateWithModel.
    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 ); }, };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rawveg/ollama-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server