Skip to content

Conversation

@nouamanecodes
Copy link

Hey guys, I went ahead and enhanced the repo into a working CLI. That way prompt learning can be run from anywhere including CICD, and large sets of prompts can be optimized at once

The main updates

Faster token counting - Large datasets won't make you wait anymore. Vectorized pandas operations instead of slow row-by-row processing.

Google AI integration - Full Gemini support with search grounding and image generation ("nano banana"). No more being locked into just OpenAI.

Budget controls - Real-time pricing with automatic stops at $5 default.

Production-ready CLI - Pure Python Click interface. Comprehensive help, verbose logging, error handling.

Ready for PyPI - Ideally users would just do pip install prompt-learn. then prompt-learn <args>. See README_enhanced.md

Real Performance Numbers

(See tests/benchmarks/PERFORMANCE_OPTIMIZATION_REPORT.md)

Dataset Size Component Before After Improvement
Large (10K rows) TikToken 55.3s 49.8s 1.1x faster
Large (10K rows) Approximate 1.6s 0.2s 7.3x faster
Large (10K rows) Batch Split 2.0s 0.4s 5.7x faster

The big win: vectorized operations in interfaces/token_counter.py replaced df.iterrows() with pandas .apply().

New CLI Commands

# Optimize with budget control
prompt-learn optimize --prompt "Your prompt" --dataset data.csv --budget 10.00

# Image generation with nano banana
prompt-learn image --prompt "A futuristic cityscape" --evaluate

# Verbose mode shows costs in real-time
prompt-learn --verbose optimize -p "Your prompt" -d data.csv -f feedback

Architecture Fixes

Clean dependency injection, provider abstractions, custom exceptions, centralized config.

New modules:

  • interfaces/token_counter.py - Token counting without model coupling
  • providers/base_provider.py - Clean AI provider interface
  • core/pricing.py - Real-time cost tracking and budget enforcement
  • core/exceptions.py - Proper error hierarchy

Google AI Integration

Full Gemini support with search grounding. Image generation includes human-in-the-loop evaluation since image quality is subjective.

# Dependency injection makes providers swappable
optimizer = PromptLearningOptimizer(
    prompt="Your prompt",
    model_choice="gemini-2.5-flash",
    provider=GoogleProvider(),
    budget_limit=5.0
)

Budget Controls

Uses https://pricepertoken.com/ pricing data. Stops optimization before hitting limits.

class PricingCalculator:
    def would_exceed_budget(self, model: str, input_tokens: int, 
                           output_tokens: int, budget_limit: float) -> bool:
        additional_cost = self.calculate_cost(model, input_tokens, output_tokens)
        return (self.total_cost + additional_cost) > budget_limit

Ready to merge and ship to PyPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant