A TypeScript application that uses Google's Gemini AI to generate content based on configurable goals and guidelines, with automatic evaluation and retry logic to ensure quality.
- PromptOrchestrator: Converts goals and guidelines into structured LLM prompts
- GeminiService: Handles communication with Google's Gemini AI API with unlimited token generation
- Evaluator: Automatically evaluates generated content against guidelines using AI
- Smart Retry System: Automatically retries generation with enhanced prompts when content doesn't meet quality standards
- Manual Score Calculation: Calculates scores based on percentage of guidelines passed
- TypeScript: Full type safety and modern development experience
- Node.js 16+
- TypeScript 5+
- Valid Gemini API key
-
Install dependencies:
npm install
-
Get your Gemini API key:
- Visit Google AI Studio
- Create a new API key
- Copy the key
-
Set up environment variables: Create a
.envfile in the project root:GEMINI_API_KEY=your_actual_api_key_here
-
Run the application:
npm start
The application will:
- Generate a structured prompt from your goal and guidelines
- Send the prompt to Gemini AI for content generation
- Automatically evaluate the generated content against all guidelines
- Calculate a score based on the percentage of guidelines that passed
- If the score meets the threshold (100% by default), display the accepted content
- If not, retry with enhanced prompts focusing on failed guidelines (up to 3 attempts)
- Display the best result if all attempts fail to meet the threshold
You can modify the following in main.ts:
- Goal: The main objective for content generation (line 8)
- Guidelines: Array of requirements the content must meet (lines 10-18)
- MAX_ATTEMPTS: Number of retry attempts (default: 3)
- SCORE_THRESHOLD: Minimum score percentage to accept content (default: 100%)
generatePrompt(failedGuidelines?): Creates a formatted LLM prompt, optionally emphasizing previously failed guidelinessetGoal(goal): Updates the content generation goalsetGuidelines(guidelines): Updates the guidelines arrayaddGuideline(guideline): Adds a single guidelinegetGoal(): Returns the current goalgetGuidelines(): Returns a copy of current guidelines
generateContent(prompt, temperature?): Generates content with optional temperature control (default: 0.7)
evaluateContent(content, goal, guidelines): Evaluates content against guidelines and returns score, feedback, and detailed results
The application uses a sophisticated evaluation system:
- AI-Powered Assessment: Uses Gemini AI to evaluate each guideline individually
- Manual Score Calculation: Calculates the final score as
(passed guidelines / total guidelines) * 100 - Detailed Feedback: Provides specific feedback on which guidelines were met or missed
- Smart Retry Logic: If content doesn't meet the threshold, retries with enhanced prompts that focus on previously failed guidelines
- Transparent Results: Shows detailed breakdown of which guidelines passed/failed for each attempt