LLM-powered conversation interface with intelligent context management, real-time search integration, and seamless conversation flow
Project description
PromptLifter
A conversation-focused LLM interface with intelligent context management, optional search integration, and optimized LLM interactions for conversational AI applications. Features real-time web search, vector database integration, and seamless conversation flow with automatic context optimization.
โจ Features
- Conversation-Focused: Maintains conversation history with automatic summarization and context flow
- Intelligent Context Management: Automatic context optimization for LLM token limits with smart relevance filtering
- Real-Time Search Integration: Conditional web search (Tavily) and vector search (Pinecone) with context-aware triggering
- Seamless Conversation Flow: Builds upon previous interactions for natural, context-aware responses
- Multiple LLM Support: OpenAI, Anthropic, Google, and custom/local LLM endpoints (Ollama, Lambda Labs, Together AI)
- Smart Embedding Service: Automatic fallback embedding with support for custom and commercial providers
- Production Ready: Security-hardened, optimized, and thoroughly tested with 115+ test cases
- Flexible Configuration: Configurable search behavior, token limits, and context strategies
๐ Quick Start
Installation
From PyPI (Recommended)
pip install promptlifter
From Source
git clone https://github.com/promptlifter/promptlifter
cd promptlifter
pip install -e .
Basic Usage
import asyncio
from promptlifter import ConversationLLM
async def main():
# Initialize conversation LLM
llm = ConversationLLM()
# Start a conversation
response = await llm.chat("What is machine learning?")
print(response.message)
# Follow-up with context (automatically uses previous conversation)
response = await llm.chat("Can you give me an example?")
print(response.message)
if __name__ == "__main__":
asyncio.run(main())
Quick Chat Function
import asyncio
from promptlifter import quick_chat
async def main():
# One-liner for simple interactions
response = await quick_chat("Explain quantum computing")
print(response)
if __name__ == "__main__":
asyncio.run(main())
Command Line Usage
# Interactive mode
promptlifter --interactive
# Single query
promptlifter --query "Research AI in healthcare applications"
# Save results to file
promptlifter --query "Quantum computing research" --save results.json
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER INTERFACE โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ CLI โ โ Python API โ โ Interactive โ โ
โ โ Interface โ โ โ โ Mode โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MAIN APPLICATION โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ConversationLLM โ โ
โ โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Conversation โ โ Context โ โ Context โ โ โ
โ โ โ Manager โ โ Retriever โ โ Optimizer โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SERVICES LAYER โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ LLM โ โ Embedding โ โ Tavily โ โ Pinecone โ โ
โ โ Service โ โ Service โ โ Search โ โ Vector โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ EXTERNAL PROVIDERS โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ OpenAI โ โ Anthropic โ โ Google โ โ Custom โ โ
โ โ API โ โ API โ โ API โ โ LLM โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Web โ โ Vector โ โ Local โ โ Remote โ โ
โ โ Content โ โ Database โ โ Models โ โ Services โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
DATA FLOW:
User Input โ CLI/API โ Main App โ ConversationLLM โ Context Management
โ
External Search โ Context Retriever โ Context Analysis
โ
LLM Processing โ Context Optimizer โ Search Results + History
โ
Response Generation โ User Output
๐ง Setup
1. Clone the Repository
git clone https://github.com/promptlifter/promptlifter
cd promptlifter
2. Install Dependencies
Option 1: Install from Source
pip install -e .
Option 2: Install with Development Dependencies
pip install -e ".[dev]"
Option 3: Install with Test Dependencies
pip install -e ".[test]"
3. Configure Environment Variables
Copy the example environment file and configure your API keys:
cp env.example .env
Edit .env with your configuration:
# Custom LLM Configuration (Primary - Local Models or OpenAI-Compatible APIs)
CUSTOM_LLM_ENDPOINT=http://localhost:11434
CUSTOM_LLM_MODEL=llama3.1
CUSTOM_LLM_API_KEY=
# LLM Provider Configuration (Choose ONE provider)
LLM_PROVIDER=custom # custom, openai, anthropic, google
# Embedding Configuration (Choose ONE provider)
EMBEDDING_PROVIDER=custom # custom, openai, anthropic
EMBEDDING_MODEL=nomic-embed-text # Ollama embedding model (for custom provider) or OpenAI model name
# Commercial LLM Configuration (API keys for non-custom providers)
OPENAI_API_KEY=your-openai-api-key-here
ANTHROPIC_API_KEY=your-anthropic-api-key-here
GOOGLE_API_KEY=your-google-api-key-here
# Search and Vector Configuration (Optional)
TAVILY_API_KEY=your-tavily-api-key-here
PINECONE_API_KEY=your-pinecone-api-key-here
PINECONE_INDEX=your-pinecone-index-name-here
PINECONE_NAMESPACE=research
# Conversation Context Settings
MAX_HISTORY_TOKENS=4000 # Maximum tokens for conversation history
MAX_CONTEXT_TOKENS=2000 # Maximum tokens for context assembly
ENABLE_AUTO_SEARCH=true # Enable automatic search
SEARCH_RELEVANCE_THRESHOLD=0.7 # Minimum relevance score for search results
# Pinecone Search Configuration (Optional)
PINECONE_TOP_K=10 # Number of results (default: 10)
PINECONE_SIMILARITY_THRESHOLD=0.7 # Minimum similarity (0.0-1.0)
PINECONE_INCLUDE_SCORES=true # Show similarity scores
PINECONE_FILTER_BY_SCORE=true # Filter by threshold
4. Set Up LLM Providers
Option 1: Local LLM (Recommended - No API Keys Needed)
Using Ollama (Easiest)
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# Pull Llama 3.1 model
ollama pull llama3.1
# Start Ollama server
ollama serve
Using Other Local LLM Servers
- LM Studio: Run with OpenAI-compatible API
- vLLM: Fast inference server
- Custom endpoints: Any OpenAI-compatible API
Option 2: OpenAI-Compatible APIs (Requires API Keys)
Lambda Labs Setup
- Get API key from https://cloud.lambdalabs.com/
- Add to
.env:
CUSTOM_LLM_ENDPOINT=https://api.lambda.ai/v1
CUSTOM_LLM_MODEL=llama-4-maverick-17b-128e-instruct-fp8
CUSTOM_LLM_API_KEY=your-lambda-api-key-here
Together AI Setup
- Get API key from https://together.ai/
- Add to
.env:
CUSTOM_LLM_ENDPOINT=https://api.together.xyz/v1
CUSTOM_LLM_MODEL=meta-llama/Llama-3.1-8B-Instruct
CUSTOM_LLM_API_KEY=your-together-api-key-here
Perplexity AI Setup
- Get API key from https://www.perplexity.ai/
- Add to
.env:
CUSTOM_LLM_ENDPOINT=https://api.perplexity.ai
CUSTOM_LLM_MODEL=llama-3.1-8b-instruct
CUSTOM_LLM_API_KEY=your-perplexity-api-key-here
Option 3: Commercial LLM (Fallback)
OpenAI Setup
- Get API key from https://platform.openai.com/api-keys
- Add to
.env:
OPENAI_API_KEY=sk-your-actual-key-here
Anthropic Setup
- Get API key from https://console.anthropic.com/
- Add to
.env:
ANTHROPIC_API_KEY=sk-ant-your-actual-key-here
Google Setup
- Get API key from https://makersuite.google.com/app/apikey
- Add to
.env:
GOOGLE_API_KEY=your-actual-key-here
5. Run the Application
Interactive Mode
promptlifter --interactive
# or
python -m promptlifter.main --interactive
Single Query Mode
promptlifter --query "Research quantum computing trends"
# or
python -m promptlifter.main --query "Research quantum computing trends"
6. Run Tests
# Run all tests
python run_tests.py
# Run specific tests
python run_tests.py config
# Run with pytest directly
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=promptlifter --cov-report=html
๐ Recent Improvements (v0.5.0+)
Enhanced Context Management
- Simplified Relevance Scoring: Removed complex keyword matching in favor of trusting search engine results
- Improved Conversation Flow: Better follow-up question handling with context-aware search triggering
- Fixed Embedding Issues: Resolved 400 errors with custom embedding models and improved fallback handling
Smart Search Integration
- Context-Aware Search: Follow-up questions now properly use conversation context instead of unnecessary external searches
- Real-Time Web Search: Tavily integration provides current information for weather, news, and research queries
- Vector Database Support: Pinecone integration for knowledge base queries with similarity scoring
Production Ready
- 115+ Test Cases: Comprehensive test coverage including unit, integration, and configuration tests
- Clean Architecture: Simplified codebase with removed complexity and improved maintainability
- Better Error Handling: Graceful fallbacks and improved error messages
Key Fixes in v0.5.0
- โ Fixed Embedding Service: Resolved 400 errors when using custom embedding models with Ollama
- โ Improved Context Flow: Follow-up questions now maintain conversation context properly
- โ Simplified Relevance Logic: Removed brittle keyword matching for more reliable search results
- โ Enhanced Test Coverage: All 115 tests passing with comprehensive coverage
- โ Better Error Messages: More informative error handling and debugging information
๐ How It Works
Conversation-Focused Architecture
- Query Input: User provides a message or question
- Context Analysis: System determines if external search is needed
- Intelligent Search: When needed, performs web and/or vector search
- Context Assembly: Combines conversation history with search results
- LLM Processing: Generates response using optimized context
- History Management: Updates conversation history with new interaction
Key Components
ConversationLLM
- Main interface for conversational interactions
- Manages conversation history and context
- Handles search integration automatically
ConversationContextManager
- Maintains conversation history with automatic summarization
- Manages token limits and context optimization
- Provides conversation statistics and export/import
ContextRetriever
- Intelligently determines when search is needed
- Performs conditional web and vector search
- Filters results by relevance
ContextOptimizer
- Assembles optimal context for LLM inference
- Manages token limits and compression
- Prioritizes most relevant information
๐ฏ Configuration Options
Conversation Settings
| Setting | Type | Default | Description |
|---|---|---|---|
max_history_tokens |
int | 4000 | Maximum tokens to keep in conversation history |
max_context_tokens |
int | 2000 | Maximum tokens for context assembly |
enable_auto_search |
bool | true | Enable automatic search when needed |
search_relevance_threshold |
float | 0.7 | Minimum relevance score for search results |
system_prompt |
str | "You are a helpful assistant." | System prompt for LLM |
Search Configuration
| Setting | Type | Default | Description |
|---|---|---|---|
PINECONE_TOP_K |
int | 10 | Number of results to retrieve |
PINECONE_SIMILARITY_THRESHOLD |
float | 0.7 | Minimum similarity score (0.0-1.0) |
PINECONE_INCLUDE_SCORES |
bool | true | Include similarity scores in output |
PINECONE_FILTER_BY_SCORE |
bool | true | Filter results by similarity threshold |
๐ Advanced Usage
Custom Configuration
import asyncio
from promptlifter import ConversationLLM, ConversationConfig
async def main():
# Create custom configuration
config = ConversationConfig(
max_history_tokens=3000,
max_context_tokens=1500,
enable_auto_search=True,
search_relevance_threshold=0.8,
system_prompt="You are a research assistant specializing in AI."
)
# Initialize with custom config
llm = ConversationLLM(config)
# Use the configured LLM
response = await llm.chat("What are the latest AI trends?")
print(response.message)
if __name__ == "__main__":
asyncio.run(main())
Conversation Management
# Get conversation statistics
stats = llm.get_conversation_stats()
print(f"Total turns: {stats['total_turns']}")
print(f"Current tokens: {stats['current_tokens']}")
# Export conversation history
history = llm.export_conversation()
print(f"Exported {len(history)} conversation turns")
# Clear conversation
llm.clear_conversation()
# Import conversation history
llm.import_conversation(history)
Search Statistics
# Get retrieval statistics
retrieval_stats = llm.get_retrieval_stats()
print(f"Tavily enabled: {retrieval_stats['tavily_enabled']}")
print(f"Pinecone enabled: {retrieval_stats['pinecone_enabled']}")
# Get optimization statistics
optimization_stats = llm.get_optimization_stats()
print(f"Max tokens: {optimization_stats['max_tokens']}")
print(f"Compression enabled: {optimization_stats['compression_enabled']}")
๐ ๏ธ Troubleshooting
Common Issues
No Search Results
- Check if
ENABLE_AUTO_SEARCH=trueand API keys are configured - Verify Tavily and Pinecone API keys are valid
- Check if your Pinecone index has data
Context Too Long
- Reduce
MAX_CONTEXT_TOKENSor enable compression - Lower
MAX_HISTORY_TOKENSto keep less history - Clear conversation regularly with
llm.clear_conversation()
Memory Issues
- Reduce
MAX_HISTORY_TOKENSor clear conversation regularly - Use smaller context windows
- Enable context compression
API Errors
- Verify API keys are correct and have sufficient credits
- Check API service status
- Review rate limiting settings
Debug Information
import asyncio
import logging
from promptlifter import ConversationLLM
async def debug_example():
# Enable detailed logging
logging.basicConfig(level=logging.INFO)
# Initialize LLM
llm = ConversationLLM()
# Get detailed response information
response = await llm.chat("Your question")
print(f"Context sources: {response.context_sources}")
print(f"Tokens used: {response.tokens_used}")
print(f"Conversation stats: {response.conversation_stats}")
if __name__ == "__main__":
asyncio.run(debug_example())
Search Debugging
# Get search statistics
retrieval_stats = llm.get_retrieval_stats()
print(f"Retrieval: {retrieval_stats}")
# Get optimization statistics
optimization_stats = llm.get_optimization_stats()
print(f"Optimization: {optimization_stats}")
๐ฆ Development & Release
For Developers
# Install development dependencies
pip install -e ".[dev]"
# Run quality checks
tox
# Run tests
pytest tests/ -v
# Format code
black promptlifter tests
For Contributors
Please see the project repository for development guidelines and contribution instructions.
Release Process
# Setup PyPI credentials
python scripts/setup_pypi.py
# Test release to TestPyPI
python scripts/release.py test
# Release to PyPI
python scripts/release.py release
๐งช Testing
The project includes comprehensive test coverage:
- Unit Tests: Individual component testing
- Integration Tests: End-to-end functionality testing
- Configuration Tests: Environment and setup validation
- Service Tests: LLM and embedding service testing
Running Tests
# Run all tests
pytest tests/ -v
# Run specific test suites
pytest tests/test_conversation_interface_simple.py -v
pytest tests/test_conversation_interface.py::TestIntegration -v
# Run with coverage
pytest tests/ --cov=promptlifter --cov-report=html
๐ Security & Quality
The codebase has been thoroughly audited for security and quality:
- Security Hardened: No vulnerabilities, secure coding practices
- Code Quality: No unused code, optimized imports, clean structure
- Production Ready: Comprehensive testing, proper logging, error handling
- Maintainable: Clean architecture, well-documented, consistent style
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Please see the project repository for detailed contribution guidelines.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptlifter-0.5.0.tar.gz.
File metadata
- Download URL: promptlifter-0.5.0.tar.gz
- Upload date:
- Size: 54.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9a54eb331bcbfa9bf35dd500a7ee8bb7c8be1d0a24bee1226f31991f723c7e2
|
|
| MD5 |
932475a0bc05a08e76ee34d096f62600
|
|
| BLAKE2b-256 |
7f440de39e5fd684348cbf883f4803f0b8fdea166c43dcc635f0350b0851d045
|
File details
Details for the file promptlifter-0.5.0-py3-none-any.whl.
File metadata
- Download URL: promptlifter-0.5.0-py3-none-any.whl
- Upload date:
- Size: 37.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52859d04489597387e3b04c9802ef64946d09dbba680a4aac0d23e8576d2fb84
|
|
| MD5 |
56a5828a3be83f66f4c8ef378542e62c
|
|
| BLAKE2b-256 |
c13ff1285d1248bb9e5b95d98c1ca5b2627fa893f1c2a9a42b09d712163c2e2a
|