Genpower
Generate reliable, typed outputs from LLMs with schema validation and retry logic.
Genpower is a lightweight TypeScript library that helps developers integrate GenAI models like OpenAI, Gemini, and others into apps — with structured JSON output, schema validation (using Zod), and automatic retries if the model output is invalid.
Perfect for apps where you need reliable AI responses, not just raw text.
Features
- Plug-and-play support for OpenAI (ChatGPT), Gemini (Google)
- Use Zod schemas to define and validate output structure
- Auto-retry when output doesn't match the schema
- Works in TypeScript/JavaScript apps (including React Native)
- Easy to extend to other providers
Example
const WeatherSchema = z.object({
location: z.string(),
temperature: z.number(),
condition: z.string(),
});
const generator = new PromptGenerator(
new OpenAIEngine("your-api-key"),
WeatherSchema,
"What’s the current weather in {city}? Return JSON with location, temperature, condition."
);
const result = await generator.generate({ city: "Berlin" });
Install
npm install genpower
# or
yarn add genpower
Prerequisites
This package relies on Zod for schema validation and parsing.
Please install Zod in your project:
npm install zod
# or
yarn add zod
Documentation
Coming soon
License
MIT — free for personal and commercial use
Want to contribute or support?
If you're interested in collaborating, supporting further development, or sharing ideas, feel free to DM me on GitHub