Skip to main content

Library to test prompt quality

Project description

LLM Prompt Evaluation Tool

This tool allows you to evaluate how well your LLM response matches your ideal answer by comparing generated questions (from ideal answer) and answers (from llm response). The tool also supports visualizing your test scores on a chart, with results automatically grouped by different prompt IDs.

Key Parameters

  • ideal_answer: str (required):
    The ideal answer for your prompt.

  • llm_response: str (required):
    Your LLM's response.

  • optional_params: dict (optional):
    A JSON-like dictionary that may include extra details for the test. For now you can pass prompt_id key to link test results to this prompt_id Example:

    {
      "prompt_id": "blockchain_prompt"
    }
    

Using the Tool

1. Pass ideal_answer, llm_response

User calls the compare() method by passing the ideal_answer: str and llm_response: str and (optionally) optional_params: dict parameters. compare() method returns an object with test results.

Example:

from lamoom_cicd import TestLLMResponsePipe

# Users must provide these values (it doesn't matter how they obtain them)
ideal_answer = "Your ideal answer here"  # Replace with the expected response
llm_response = "Your LLM-generated response here"  # Replace with the model's actual response

# Optional: If you have a prompt_id, you can link results to it
optional_params = {
    "prompt_id": "your_prompt_id"  # Replace with an actual prompt identifier if needed
}

lamoom_pipe = TestLLMResponsePipe(openai_key=os.environ.get("OPENAI_KEY"))

# Compare the ideal answer with the LLM's response
result = lamoom_pipe.compare(ideal_answer, llm_response, optional_params=optional_params)

# Print test questions details
for question in result.questions:
    print(question.to_dict())

# Print final test score
print(result.score.to_dict())

2. Pass a CSV file

You can also pass multiple test cases using a CSV file. The CSV file should contain the following columns:

  • ideal_answer: (Required) The ideal answer.
  • llm_response: (Required) Your LLM response.
  • optional_params: (Optional) A JSON string containing the optional parameters.

If multiple rows are added then multiple test will run.

Example CSV Content: IMPORTANT: take notice of double quotes when putting json in a csv file!

ideal_answer,llm_response, optional_params
"Blockchain is a secure, immutable digital ledger.","Blockchain is like a shared Google Doc that records every change.","{""prompt_id"": ""blockchain_prompt""}", 

Usage Example:

csv_file_path = "your_file.csv"
lamoom_pipe = TestLLMResponsePipe(openai_key="your_key")
accumulated_results: list = lamoom_pipe.compare_from_csv(csv_file_path)

3. Visualizing Test Scores

After running tests, the results are automatically accumulated by prompt_id. To see a visual chart of test scores, use the provided visualization function.

Example:

lamoom_pipe.visualize_test_results()

This function will generate a line chart with the x-axis representing the test instance number (as integers) and the y-axis representing the score percentage. Each line on the chart corresponds to a different prompt_id.

Enjoy using the tool to refine and evaluate your LLM prompts!

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

lamoom_cicd-0.1.6.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

lamoom_cicd-0.1.6-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file lamoom_cicd-0.1.6.tar.gz.

File metadata

  • Download URL: lamoom_cicd-0.1.6.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for lamoom_cicd-0.1.6.tar.gz
Algorithm Hash digest
SHA256 d5cc680f503dd429e07659a2cddd7cf46294c356482e0bc9c872ef7c5b00b2e1
MD5 719472e907c8d89c97cfd3f8756970d6
BLAKE2b-256 3f46afcdd6360e2baa1309b8eb5d311261c749758ed2bfcd06bcd8513a67faea

See more details on using hashes here.

File details

Details for the file lamoom_cicd-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: lamoom_cicd-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.11 Linux/6.8.0-1021-azure

File hashes

Hashes for lamoom_cicd-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9a429e6106659a25575349169d693f88761add7a5764a74dad1a1e650bf5a7c8
MD5 a020354120eca683644e3d8be9630d51
BLAKE2b-256 9f94e931f9b3cf327c4a5e5baed8f524dbb5c1654b58b757a8083dfb3bc7a110

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