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.
- 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
- Go 1.21 or later
- Access to an OpenAI-compatible API endpoint
go get github.com/yourusername/promptimalpackage 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)
}
}PopulationSize: Number of prompts in each generationNumIterations: Number of evolution cyclesNumElites: Number of best prompts to preserve between generationsThreshold: Target fitness score (0.0 - 1.0)ImprovementRequest: Description of desired improvementsMaxThreads: Maximum number of concurrent evaluationsOpenAIModel: Model identifier for the APIOpenAIBaseURL: API endpoint URLOpenAIAPIKey: Authentication token
- Initialization: Generates an initial population of prompts based on the input prompt
- Evaluation: Assesses each prompt's fitness using the LLM
- Selection: Chooses the best-performing prompts
- Crossover: Combines successful prompts to create new variations
- Iteration: Repeats the process until reaching the target threshold or iteration limit
Prompts are evaluated based on:
- Clarity
- Context
- Specificity
- Guidance
- Examples
- Role Definition
- Boundaries
- Reasoning
- Flexibility
- Structure
Contributions are welcome! Please feel free to submit pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
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.