Skip to main content

Package for generating AI prompts and answers

Project description

Prompt and Answer Generation Tool

This tool generates structured conversations (prompts and answers) based on specified topics using language models.

Requirements

  • Requires LiteLLM for API access

Features

  • Generate multiple prompts per topic
  • Generate assistant answers for each prompt
  • Save conversations to JSON file
  • Environment variables for configuration
  • Interactive prompts for missing values
  • Batch processing for prompt/answer generation
  • Asynchronous API calls for improved performance

Setup

  1. Install dependencies:
pip install python-dotenv litellm

Migration

To convert existing conversations files:

python migrate.py conversations.json

The script will:

  1. Create a backup (filename + ".bak")
  2. Convert all \n sequences to actual newlines
  3. Save the updated file
  4. Create a .env file (optional) with your environment variables:
PROMPTGEN_MODEL=<your_prompt_generation_model>
ANSWERGEN_MODEL=<your_answer_generation_model>[,<other_models>]
TEMPERATURE=0.7
TOPICS=topic1,topic2
AMOUNTS=3,2
MULTI_PROMPT=y
LOGITS=y    # Set to y to enable logits capture
OUTPUT_FILE=my_conversations.json
MODEL_SPLIT=50,25,25   # For multiple answer models, comma-separated percentages (sum=100)

API Keys

Set API keys using environment variables before running:

export OPENAI_API_KEY=sk-xxxx  # For OpenAI models
export ANTHROPIC_API_KEY=sk-xxxx  # For Claude models

The key required depends on your preferred provider:

Logits Capture

When LOGITS=y:

  • Assistant responses will include token-level probability data from the model
  • This data includes the top 10 token candidates at each position with their log probabilities

Environment Variables

Variable Description Default
PROMPTGEN_MODEL Model for prompt generation Required
ANSWERGEN_MODEL Model for answer generation Required
TEMPERATURE Creativity level (0.0-1.0) 0.7
TOPICS Comma-separated list of topics Required
AMOUNTS Number of prompts per topic (single or comma-separated) Required
MULTI_PROMPT Use multi-prompt generation? (Y/n) y
MODEL_SPLIT Percentage split for answer models (comma-separated, sum=100) Required for multiple models
LOGITS Use logits for answer generation? (y/n) n
OUTPUT_FILE Output JSON filename conversations.json
BATCH_SIZE Batch size for prompt generation 5
ASYNC_GEN Enable asynchronous generation? (y/n) n
VERBOSE_LOGGING Print request/response bodies n

Usage

Run the script:

python main.py

The tool will:

  1. Check for required environment variables
  2. Prompt for missing values
  3. Generate prompts for each topic
  4. Generate answers for each prompt
  5. Save conversations to specified JSON file

Output Format

Conversations are saved in JSON format:

[
  {
    "messages": [
      {
        "role": "user",
        "content": "Explain quantum computing in simple terms",
        "generation_model": "gpt-3.5-turbo"  // New field for prompt model
      },
      {
        "role": "assistant",
        "content": "Quantum computing leverages quantum mechanics to process information...",
        "logprobs": {
          "content": [
            {
              "token": "Quantum",
              "logprob": -0.1,
              "top_logprobs": [
                {"token": "Quantum", "logprob": -0.1},
                {"token": "This", "logprob": -1.2},
                ...
              ]
            }
          ]
        },
        "generation_model": "gpt-4"  // New field for answer model
      }
    ],
    "model": "gpt-4"  // Model used for answer generation in this conversation
  }
]
  • The conversation object now includes a top-level "model" field indicating the answer generation model
  • User messages include "generation_model" showing which model created the prompt

Example

# .env file:
PROMPTGEN_MODEL=gpt-3.5-turbo
ANSWERGEN_MODEL=gpt-4
TOPICS=Python,JavaScript
AMOUNTS=2
BATCH_SIZE=5          # Add this line
ASYNC_GEN=n           # Add this line

# Command:
python main.py

Notes

  • Uses LiteLLM format for API access
  • Check .env.example for configuration reference

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

mypromptgen-0.2.0.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

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

mypromptgen-0.2.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file mypromptgen-0.2.0.tar.gz.

File metadata

  • Download URL: mypromptgen-0.2.0.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for mypromptgen-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1a4e8be578346a9844235b4710e9ae51df4e5908719a27666eb9b684b22dbfdc
MD5 25f89983cfd4d53c395fbe1d45dc80e4
BLAKE2b-256 86571db379bff56d7bb4a7debff1cecfbad50230a5a82a32089f66d81de1dcc0

See more details on using hashes here.

File details

Details for the file mypromptgen-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mypromptgen-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for mypromptgen-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85df73ee0749c81490a12e8fdb4f5ab4b0b69847048d07d52d5246dae641fbd1
MD5 4364f7aa2637311d6f168d25a939a53f
BLAKE2b-256 b0c8be2729414015ccc5820283cf32d57af02ad2c4b981a4903c41f0438a301c

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