Skip to main content

No project description provided

Project description

PyPI version

Genetic Prompt Compiler

Optimize a prompt for a language model using a genetic algorithm.

import genetic_compiler
from genetic_compiler import GeneticCompilerArgs

initial_prompt = ""

rules = [
    "Rule 1",
    "Rule 2",
    "Rule 3",
]

test_data [
    ("Question 1", "Answer 1"),
    ("Question 2", "Answer 2"),
    ("Question 3", "Answer 3"),
]

args = GeneticCompilerArgs(
    # The rating notation to use (X/10, X/5 etc.)
    rating_notation=10,
    # Amount of examples to test on prompts in each generation
    example_amount=3,
    # Top n prompts to keep in each generation
    top_n=3,
    # Amount of prompts to generate in each generation
    popultation_size=8,
    # Amount of generations to run
    iterations=3,
    # Initial prompt to start with.
    # This prompt will be kept for the first generation, alongside propulation_size - 1 mutated versions of it
    initial_prompt=initial_prompt,
    # Rules to test the prompts on
    rules=rules,
    # Log level
    log_level="INFO",
    # Test data to test the prompts on (Currently only the answers are used)
    train_data=train_data,
    # LiteLLM arguments for the fitness model (This llm will evaluate the prompts)
    fitness_model_args={
        "model": "gpt-4",
        "temperature": 0.1,
    },
    # LiteLLM arguments for the student model (This is the llm we want to optimize)
    student_model_args={
        "model": "openai/TheBloke/Mistral-7B-Instruct-v0.2-AWQ",
        "api_base": "http://127.0.0.1:8000/v1",
        "temperature": 0.1,
    },
    # LiteLLM arguments for the mutation model (This llm will mutate the prompts)
    mutation_model_args={
        "model": "gpt-4",
        "temperature": 0.3,
    },
)

for population in genetic_compiler.run(args):
    top_prompt = population[0]
    print(f"Top prompt: {top_prompt}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genetic_prompt_compiler-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

genetic_prompt_compiler-0.1.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file genetic_prompt_compiler-0.1.2.tar.gz.

File metadata

  • Download URL: genetic_prompt_compiler-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for genetic_prompt_compiler-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4ffff03e946e8f7e268b476382efda807feeaccc8c5565479325814358f9fdde
MD5 83dc6c2f9e6962072774001dbecfa736
BLAKE2b-256 c236d79734a792ba97fb1dac72890349ddaf8b003ffe1e7b74c859d0e994dfa1

See more details on using hashes here.

File details

Details for the file genetic_prompt_compiler-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for genetic_prompt_compiler-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 65f0e3bc3cce0c8c6f15dbca3554f6b8a5e4fc2dc702103b3242925cbeb33037
MD5 ad93df6d621885c48d8413a488585fdc
BLAKE2b-256 3e63e2477e52fa7f55c7dc7b7db732b2fe319660f0800d677abbebf7483fcbbe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page