A Python library for building AI agents
Project description
PepperPy
PepperPy is a Python framework for building AI agents with advanced conversation, memory, and knowledge retrieval capabilities.
Features
Conversation Management
- Track conversation history with context
- Support for system, user, assistant, and function messages
- Save and load conversations
- Metadata and timestamp tracking
Memory System
- Short-term and long-term memory management
- Memory importance scoring
- Memory consolidation and retrieval
- Flexible storage backends
Retrieval Augmented Generation (RAG)
- Document chunking with multiple strategies
- Vector storage for semantic search
- Embedding generation and similarity search
- Context-aware text generation
LLM Provider Management
- Multiple provider support
- Automatic fallback handling
- Provider statistics tracking
- Streaming response support
Installation
pip install pepperpy
Quick Start
Basic Usage
import asyncio
from pepperpy.llms.llm_manager import LLMManager
async def main():
# Initialize LLM manager
llm_manager = LLMManager()
await llm_manager.initialize({
"primary": {
"type": "openrouter",
"model_name": "anthropic/claude-2",
"api_key": "your-api-key"
}
})
try:
# Generate text
response = await llm_manager.generate("Hello, world!")
print(response.text)
finally:
await llm_manager.cleanup()
if __name__ == "__main__":
asyncio.run(main())
Using Conversation and Memory
from datetime import datetime
from pepperpy.persistence.storage.conversation import Conversation, Message, MessageRole
from pepperpy.providers.memory import MemoryManager
# Create conversation
conversation = Conversation()
conversation.add_message(
Message(
role=MessageRole.SYSTEM,
content="You are a helpful assistant.",
timestamp=datetime.now()
)
)
# Create memory manager
memory_manager = MemoryManager()
await memory_manager.add_memory(
content="User likes Python programming",
importance=0.8,
metadata={"type": "preference"}
)
# Query memories
relevant_memories = await memory_manager.query(
"What does the user like?",
limit=5
)
Using RAG
from pepperpy.persistence.storage.rag import RAGManager
from pepperpy.persistence.storage.chunking import ChunkManager
# Create RAG manager
rag_manager = RAGManager(
llm=llm_manager.get_primary_provider(),
chunk_manager=ChunkManager()
)
# Add documents
await rag_manager.add_document(
content="Document content...",
doc_id="doc1",
metadata={"type": "article"}
)
# Generate with context
response = await rag_manager.generate_with_context(
query="What is this document about?",
prompt_template=(
"Based on the following context, answer the question:\n\n"
"Context:\n{context}\n\n"
"Question: {query}\n\n"
"Answer:"
)
)
Configuration
Environment Variables
# OpenRouter API key
PEPPERPY_API_KEY=your-api-key
# Optional fallback configuration
PEPPERPY_FALLBACK_API_KEY=your-fallback-api-key
PEPPERPY_FALLBACK_MODEL=openai/gpt-4
Provider Configuration
config = {
"primary": {
"type": "openrouter",
"model_name": "anthropic/claude-2",
"api_key": "your-api-key",
"temperature": 0.7,
"max_tokens": 1000
},
"fallback": {
"type": "openrouter",
"model_name": "openai/gpt-4",
"api_key": "your-fallback-api-key",
"temperature": 0.7,
"max_tokens": 1000,
"is_fallback": True,
"priority": 1
}
}
Examples
Check out the examples directory for more detailed examples:
agent_with_memory.py: Demonstrates conversation, memory, and RAG featuresstory_illustrator.py: Shows how to use LLMs for creative tasks- More examples coming soon!
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests with
pytest - Submit a pull request
License
MIT License - see LICENSE file for details
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
pepperpy-1.2.0.tar.gz
(148.6 kB
view details)
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
pepperpy-1.2.0-py3-none-any.whl
(276.3 kB
view details)
File details
Details for the file pepperpy-1.2.0.tar.gz.
File metadata
- Download URL: pepperpy-1.2.0.tar.gz
- Upload date:
- Size: 148.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2438b5bba1de60cb89c7103bb7bac787cc5b09b7106dc802ddf8dd1d0f708091
|
|
| MD5 |
998c379439fc2859978bba895d14eef9
|
|
| BLAKE2b-256 |
4546e92e87ae2304906e4ae714eb66e58f7d343938e71340c23646fb8f84ea0c
|
File details
Details for the file pepperpy-1.2.0-py3-none-any.whl.
File metadata
- Download URL: pepperpy-1.2.0-py3-none-any.whl
- Upload date:
- Size: 276.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61dd016ec20de10740b6838968fbe3bac371a02777a023bd244d7445a6ce5d7c
|
|
| MD5 |
54dbd4adfddf2a5d82cce069fe02748c
|
|
| BLAKE2b-256 |
41cc94ab50ec3a3ecdd696a413654dfe5c088f954a6d4c78ac9c586629f69c36
|