NeuroPrompt
A smart prompt compression and optimization tool for Large Language Models that automatically adapts to different types of content and provides comprehensive quality evaluation.
Installation
To install NeuroPrompt, follow these steps:
- Set up your OpenAI API key. NeuroPrompt relies on OpenAI services, so make sure you have access to the OpenAI API.
export OPENAI_API_KEY=<your_openai_key>
- Install NeuroPrompt via
pip:
pip install neuroprompt
You can find more information about OpenAI API keys here.
Features
- Smart Prompt Compression: Compresses prompts while retaining the core information, optimizing token usage.
- Content-Aware Parameter Optimization: Automatically adapts to different types of content like code, technical lists, and text.
- Comprehensive Response Quality Evaluation: Evaluates the quality of compressed responses using standard metrics.
- Cost Optimization for OpenAI API Calls: Helps reduce the cost of API calls by minimizing token counts.
- Automatic Token Counting and Cost Estimation: Estimates the number of tokens and calculates associated costs.
Quick Start
To start using NeuroPrompt, follow the example below to implement a basic prompt compression decorator.
from neuroprompt import NeuroPromptCompress
from openai import OpenAI
@NeuroPromptCompress()
def chat_completion(messages, model="gpt-4o", temperature=0.7):
client = OpenAI()
return client.chat.completions.create(
messages=messages,
model=model,
temperature=temperature
)
# Example usage
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Your prompt here..."}
]
response = chat_completion(messages=messages)
print(response)
Documentation
Basic Usage
NeuroPrompt provides two main decorators that help you utilize prompt compression and quality evaluation features:
NeuroPromptCompress: Use this for basic prompt compression without any extra evaluation. It helps to optimize token usage and cost without checking response quality.NeuroPromptCompressWithEval: This decorator compresses prompts while also evaluating the compressed response's quality. It provides detailed insights into metrics such as relevance, coherence, and accuracy.
Advanced Features
Quality Metrics
The quality of compressed responses is measured using various standard metrics:
- ROUGE Scores: Measures the overlap of key elements between original and compressed responses.
- BLEU Score: Evaluates the similarity of the compressed response to the original text based on word overlap.
- Semantic Similarity: Uses embeddings to calculate the semantic consistency of the compressed response.
- Information Coverage: Assesses whether critical information is retained in the compressed output.
- Expert Evaluation (using GPT-4o): Applies GPT-4o to evaluate the quality of the response in terms of accuracy, completeness, and coherence.
Examples
Compressing a Chat with Evaluation
To use NeuroPrompt with evaluation metrics:
from neuroprompt import NeuroPromptCompressWithEval
from openai import OpenAI
@NeuroPromptCompressWithEval()
def chat_completion(messages, model="gpt-4o", temperature=0.7):
client = OpenAI()
return client.chat.completions.create(
messages=messages,
model=model,
temperature=temperature
)
# Example usage with evaluation
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing in simple terms."}
]
response = chat_completion(messages=messages)
print(response)
The above code will compress the prompt and provide comprehensive quality metrics, ensuring that the response remains relevant and complete.
Cost Optimization
One of NeuroPrompt's key features is reducing token usage, which directly impacts the cost of using models like GPT-4. By reducing prompt size, NeuroPrompt helps make OpenAI API usage more affordable.
License
Copyright © 2024 Tejas Chopra.
All rights reserved.
This is proprietary software. Unauthorized copying, modification, distribution, or use of this software, in whole or in part, is strictly prohibited.
Third-Party Components
This software uses LLMLingua under the MIT license. See the LICENSE file for full terms.
For more details about MIT licensing, visit the Open Source Initiative.
Support and Contributions
We welcome contributions to NeuroPrompt! If you have suggestions or find bugs, please feel free to email chopratejas@gmail.com
Metadata
Release files for neuroprompt 0.1.3
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 | Actions |
|---|---|---|---|---|
| neuroprompt-0.1.3.tar.gz | 16.4 kB | Without provenance | Details for neuroprompt-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neuroprompt-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for neuroprompt-0.1.3-py3-none-any.whl |
Total release size: 27.5 kB
Release files / neuroprompt-0.1.3.tar.gz
| Download URL | neuroprompt-0.1.3.tar.gz |
|---|---|
| Size | 16.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9a7293c9cc6e847e3d69defa55645152714a34457bb4581828972ca44e59613
|
|
BLAKE2b-256 checksum How to use checksums |
e26263f3b2f3e3da1103528f4add5bc56aa28622593a871d41f904bc737b7e02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.6
|
Release files / neuroprompt-0.1.3-py3-none-any.whl
| Download URL | neuroprompt-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6afb1cce74e77ef22c1335d8b95bb0603a6da83af09472498daf68f3eb413cc
|
|
BLAKE2b-256 checksum How to use checksums |
4ca709d5b5f25ceb92ec795080a2f81dc560b04d8f4421033eaa083d265ab440
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.6
|
Security for neuroprompt 0.1.3
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.