Skip to main content

No project description provided

Project description

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",
]

args = GeneticCompilerArgs(
    # 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,
    # VLLM arguments for the fitness model (This llm will evaluate the prompts)
    fitness_model_args={
        "model": "gpt-4",
        "temperature": 0.1,
    },
    # VLLM 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,
    },
    # VLLM 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.0.tar.gz (3.2 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.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: genetic_prompt_compiler-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 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.0.tar.gz
Algorithm Hash digest
SHA256 7dea1be07571a3a7462ac9eb94c433a9fe4d1f878a6de882bfd835f17b226c61
MD5 4829dab667703f7399a4b89cffb93a47
BLAKE2b-256 ac14190b8d11984932869792fc729406eb374e71a7a8eb87d221fb3193ce3c23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genetic_prompt_compiler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a214b456405c8d5dbfe370ccb2d60cd94f4918744904bfbd725ad808115841c4
MD5 110a0d73f8f42c587863be8b159add11
BLAKE2b-256 cf7fc6881314a3c8c5d57cc65d483dc53fa7c1448c6847a4736a274e0548e224

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