Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧬 Promptimal

Promptimal is an open-source tool that uses genetic algorithms to optimize and evolve AI prompts. It leverages the power of Large Language Models (LLMs) to generate, evaluate, and improve prompts through successive generations.

🌟 Features

  • Genetic Algorithm Optimization: Uses evolutionary algorithms to systematically improve prompts
  • Intelligent Crossover: Combines successful prompts to create even better ones
  • Custom Evaluation Metrics: Evaluates prompts based on multiple criteria including clarity, context, specificity, and more
  • Parallel Processing: Supports concurrent evaluation and optimization
  • Progress Tracking: Real-time visualization of optimization progress
  • Compatible with OpenAI API: Works with any OpenAI-compatible API endpoint

🚀 Getting Started

Prerequisites

  • Go 1.21 or later
  • Access to an OpenAI-compatible API endpoint

Installation

go get github.com/yourusername/promptimal

Basic Usage

package main

import (
    "context"
    "github.com/yourusername/promptimal"
)

func main() {
    config := promptimal.OptimizerConfig{
        PopulationSize:     10,
        NumIterations:      10,
        NumElites:          3,
        Threshold:          1.0,
        ImprovementRequest: "The prompt should be clear and concise",
        OpenAIModel:        "your-model",
        OpenAIBaseURL:      "http://your-api-endpoint",
        OpenAIAPIKey:       "your-api-key",
        MaxThreads:         4,
    }

    optimizer := promptimal.NewOptimizer(config)
    progressChan, err := optimizer.Optimize(context.Background(), "Your initial prompt")
    if err != nil {
        log.Fatal(err)
    }

    // Track optimization progress
    for progress := range progressChan {
        fmt.Printf("Progress: %.2f%%\n", progress.Value * 100)
    }
}

🛠️ Configuration Options

  • PopulationSize: Number of prompts in each generation
  • NumIterations: Number of evolution cycles
  • NumElites: Number of best prompts to preserve between generations
  • Threshold: Target fitness score (0.0 - 1.0)
  • ImprovementRequest: Description of desired improvements
  • MaxThreads: Maximum number of concurrent evaluations
  • OpenAIModel: Model identifier for the API
  • OpenAIBaseURL: API endpoint URL
  • OpenAIAPIKey: Authentication token

🧪 How It Works

  1. Initialization: Generates an initial population of prompts based on the input prompt
  2. Evaluation: Assesses each prompt's fitness using the LLM
  3. Selection: Chooses the best-performing prompts
  4. Crossover: Combines successful prompts to create new variations
  5. Iteration: Repeats the process until reaching the target threshold or iteration limit

📊 Evaluation Criteria

Prompts are evaluated based on:

  • Clarity
  • Context
  • Specificity
  • Guidance
  • Examples
  • Role Definition
  • Boundaries
  • Reasoning
  • Flexibility
  • Structure

🤝 Contributing

Contributions are welcome! Please feel free to submit pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

MIT License

Copyright (c) 2024 [Your Name]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages