LLM Parametrizer
A Python script to generate parametrized variations of prompts and get results from API calls to LLMs.
Currently only support for OpenAI’s ChatGPT is available.
Rationale
LLM respones are unpredictable and multiple tries are required to achieve the desired results when experimenting with prompts. This is a tedious process and difficult to document if done haphazardly.
This script aims at easing the process of experimenting with prompts. More importantly it aims at automatically documenting the process, making it easy to keep track of which prompts have which effects. All this while speeding up the process by parametrization and asynchrous API calls.
Dependencies
- openai
- python-dotenv
Features
- Test an API call with various parametrized values:
- Prompts
- Roles
- Models
- Temperatures
- Save as CSV to view en google sheets or similar
Parameters not yet implemented include:
- Seeds
- Frequency penalties
- Presence penalties
- Top p
Usage
First, initialize LLM_Parametrizer:
from llm_parametrizer import GPT_MODEL, LLMParametrizer
prmtrzr = LLMParametrizer()
Make sure you have a .env file with the OPEN_AI_API_KEY variable pointing to your OpenAI API key:
OPEN_AI_API_KEY=sk-proj-<your API key here>
prmtrzr.initialize_OpenAI()
Alternatively, pass your OpenAI key when initializing.
prmtrzr.initialize_OpenAI("sk-proj-<your API key here>")
You can then add prompts, models, and temperatures:
prmtrzr.add_prompts("Write a single letter of your choice")
prmtrzr.add_models(GPT_MODEL.GPT_4o.value, GPT_MODEL.GPT_3_5_T.value)
prmtrzr.add_temperatures(0.5, 1.0, 2)
The above code would generate 6 prompts (2 models times 3 temperatures).
With prmtrzr.show_parameters() you can print the parameters that have been so far added:
Prompt user: 'Write a single letter of your choice' Prompt system: 'You are a helpful assistant.' Temperature: 0.5 Model: gpt-4o
Prompt user: 'Write a single letter of your choice' Prompt system: 'You are a helpful assistant.' Temperature: 1.0 Model: gpt-4o
Prompt user: 'Write a single letter of your choice' Prompt system: 'You are a helpful assistant.' Temperature: 2 Model: gpt-4o
Prompt user: 'Write a single letter of your choice' Prompt system: 'You are a helpful assistant.' Temperature: 0.5 Model: gpt-3.5-turbo
Prompt user: 'Write a single letter of your choice' Prompt system: 'You are a helpful assistant.' Temperature: 1.0 Model: gpt-3.5-turbo
Prompt user: 'Write a single letter of your choice' Prompt system: 'You are a helpful assistant.' Temperature: 2 Model: gpt-3.5-turbo\
Use prmtrzr.show_parameters(show_raw=True) to output the full JSON that would be passed to the OpenAI API call. Use prmtrzr.return_parameters() or prmtrzr.return_parameters(return_raw=True) to return the values instead of printing them.
Finally, you can run the parameterized API calls with:
results = prmtrzr.run()
The run method returns a prettyfied string which includes the responses. So printing results with print(results) looks like this:
Prompt: 'Write a single letter of your choice' Temperature: 0.5 Model: gpt-4o Date: 2024-05-18-19-59-01 Response: A
Prompt: 'Write a single letter of your choice' Temperature: 1.0 Model: gpt-4o Date: 2024-05-18-19-59-01 Response: A
Prompt: 'Write a single letter of your choice' Temperature: 2 Model: gpt-4o Date: 2024-05-18-19-59-01 Response: L
Prompt: 'Write a single letter of your choice' Temperature: 0.5 Model: gpt-3.5-turbo Date: 2024-05-18-19-59-01 Response: A
Prompt: 'Write a single letter of your choice' Temperature: 1.0 Model: gpt-3.5-turbo Date: 2024-05-18-19-59-01 Response: G
Prompt: 'Write a single letter of your choice' Temperature: 2 Model: gpt-3.5-turbo Date: 2024-05-18-19-59-01 Response: E\
To get the raw data use:
results = prmtrzr.run(return_raw=True)
To output a csv file (viewable in google sheets for example) use:
results = prmtrzr.run(output_csv=True)
This will save a csv file viewable in google sheets or similar software:
Prompt,Temperature,Model,Time,Response Write a single letter of your choice,0.5,gpt-4o,2024-05-18-19-59-01,A Write a single letter of your choice,1.0,gpt-4o,2024-05-18-19-59-01,A Write a single letter of your choice,2,gpt-4o,2024-05-18-19-59-01,L Write a single letter of your choice,0.5,gpt-3.5-turbo,2024-05-18-19-59-01,A Write a single letter of your choice,1.0,gpt-3.5-turbo,2024-05-18-19-59-01,G Write a single letter of your choice,2,gpt-3.5-turbo,2024-05-18-19-59-01,E
License
This project is licensed under the terms of the MIT license.
Todo
- Add parameters:
- Seeds
- Frequency penalties
- Presence penalties
- Top p
- Implement APIs for other services other than OpenAI
- Implement JSON mode and function calling.
- DeepEval integration: https://github.com/confident-ai/deepeval
Metadata
Release files for llm-parametrizer 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm_parametrizer-0.1.2.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_parametrizer-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / llm_parametrizer-0.1.2.tar.gz
| Download URL | llm_parametrizer-0.1.2.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7158b0e36938940c749704b1bb8fa57a82b1325dd746ba8d1335f3060d56c8c
|
|
BLAKE2b-256 checksum How to use checksums |
a02c0fafc714ec3176f3c6f6c027ad1efa592d9dac1d2866eba57bd45205ccb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.18
|
Release files / llm_parametrizer-0.1.2-py3-none-any.whl
| Download URL | llm_parametrizer-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c3be4887f031af18c90964386338f22f0b336f5bbd1505a76882cc8f11fb72d
|
|
BLAKE2b-256 checksum How to use checksums |
89da9ca0fff4aae21054db9e0ff95260301b92c751e29290349616167b9b42c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.18
|
Security for llm-parametrizer 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.