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.3.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.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: genetic_prompt_compiler-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 5f36dd141c23a3f403832f51df192da21ce38546b693dc0d83bac10d13195cf0
MD5 e6a9518c09135592d1ceb4ccf5984eab
BLAKE2b-256 ff109a51ed55f02bb19c3ef4f83626a3e56dea76145d06b9a9a6180620455bc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genetic_prompt_compiler-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 41b65d97cad4fb61073fb4b915585774f7ac14045583ab36a88d0c0168cb152a
MD5 bfabb60f8f3b2deab05e208a8d912d5d
BLAKE2b-256 c86c36e81f03a5fce26fff8e7af57675a468cc85d892c76cc16000346056b579

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