generateText
Generate text responses from prompts using AI models, with options for reproducible results, system behavior settings, and output formats.
Instructions
Generate text from a prompt using the Pollinations Text API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The text prompt to generate a response for | |
| model | No | Model to use for text generation (default: "openai") | |
| options | No | Additional options for text generation |
Implementation Reference
- src/services/textService.js:30-69 (handler)The handler function that implements the generateText tool logic, fetching generated text from the Pollinations Text API based on the provided prompt and options.async function generateText(params) { const { prompt, model = "openai", options = {} } = params; if (!prompt || typeof prompt !== "string") { throw new Error("Prompt is required and must be a string"); } const { seed, systemPrompt, json, isPrivate } = options; // Prepare query parameters const queryParams = { model, seed, ...(systemPrompt && { system: encodeURIComponent(systemPrompt) }), ...(json && { json: "true" }), ...(isPrivate && { private: "true" }), }; // Construct the URL const encodedPrompt = encodeURIComponent(prompt); const url = buildUrl(TEXT_API_BASE_URL, encodedPrompt, queryParams); try { // Fetch the text from the URL const response = await fetch(url); if (!response.ok) { throw new Error(`Failed to generate text: ${response.statusText}`); } // Get the text response const textResponse = await response.text(); // Return the response in MCP format return createMCPResponse([createTextContent(textResponse)]); } catch (error) { console.error("Error generating text:", error); throw error; } }
- src/services/textService.js:106-141 (schema)Zod schema defining the input parameters for the generateText tool, including prompt, model, and options.prompt: z .string() .describe("The text prompt to generate a response for"), model: z .string() .optional() .describe( 'Model to use for text generation (default: "openai")', ), options: z .object({ seed: z .number() .optional() .describe("Seed for reproducible results"), systemPrompt: z .string() .optional() .describe( "Optional system prompt to set the behavior of the AI", ), json: z .boolean() .optional() .describe( "Set to true to receive response in JSON format", ), isPrivate: z .boolean() .optional() .describe( "Set to true to prevent the response from appearing in the public feed", ), }) .optional() .describe("Additional options for text generation"),
- src/services/textService.js:102-144 (registration)The registration entry for the generateText tool in the textTools array, including name, description, schema, and handler reference. This array is spread into toolDefinitions and registered via server.tool() in src/index.js.[ "generateText", "Generate text from a prompt using the Pollinations Text API", { prompt: z .string() .describe("The text prompt to generate a response for"), model: z .string() .optional() .describe( 'Model to use for text generation (default: "openai")', ), options: z .object({ seed: z .number() .optional() .describe("Seed for reproducible results"), systemPrompt: z .string() .optional() .describe( "Optional system prompt to set the behavior of the AI", ), json: z .boolean() .optional() .describe( "Set to true to receive response in JSON format", ), isPrivate: z .boolean() .optional() .describe( "Set to true to prevent the response from appearing in the public feed", ), }) .optional() .describe("Additional options for text generation"), }, generateText, ],