LLM plugin implementing Andrej Karpathy's model consortium tweet
Project description
LLM Karpathy Consortium
A sophisticated plugin for the llm package that implements an advanced model consortium system with iterative refinement and response synthesis capabilities. This plugin orchestrates multiple language models to collaboratively solve complex problems through structured dialogue and arbitration.
Features
- Multi-Model Orchestration: Coordinate responses from multiple LLMs simultaneously
- Iterative Refinement: Automatically refine responses through multiple rounds until confidence threshold is met
- Structured Response Format: XML-based response structure for consistent parsing and analysis
- Advanced Arbitration: Uses a designated arbiter model to synthesize and evaluate responses
- Database Logging: Built-in SQLite logging of all interactions and responses
- Comprehensive Error Handling: Robust error handling and logging system
- Configurable Parameters: Adjustable confidence thresholds, iteration limits, and model selection
Installation
pip install llm-karpathy-consortium
Command Line Usage
Basic usage:
llm consortium "Your prompt"
Advanced usage with options:
llm consortium "Your complex query" \
--models claude-3-opus-20240229 \
--models claude-3-sonnet-20240229 \
--models gpt-4 \
--models gemini-pro \
--arbiter-model claude-3-opus-20240229 \
--confidence-threshold 0.8 \
--max-iterations 3 \
--output results.json
Options
-m, --models: Models to include in consortium (can specify multiple)--arbiter-model: Model to use as arbiter (default: claude-3-opus-20240229)--confidence-threshold: Minimum confidence threshold (default: 0.8)--max-iterations: Maximum number of iteration rounds (default: 3)--system: Custom system prompt--output: Save full results to a JSON file
Response Structure
The plugin uses a structured XML format for responses:
<thought_process>
[Detailed reasoning about the problem]
</thought_process>
<answer>
[Final answer to the query]
</answer>
<confidence>
[Confidence level from 0 to 1]
</confidence>
Iteration Process
- Initial responses are gathered from all configured models
- The arbiter model synthesizes responses and evaluates confidence
- If confidence is below threshold and max iterations not reached:
- Refinement areas are identified
- A new iteration begins with an enhanced prompt
- Process continues until confidence threshold is met or max iterations reached
Database Logging
All interactions are automatically logged to a SQLite database located in the LLM user directory:
- Model responses
- Confidence levels
- Iteration history
- Synthesis results
- Timing information
Programmatic Usage
from llm_consortium import ConsortiumOrchestrator
orchestrator = ConsortiumOrchestrator(
models=["claude-3-opus-20240229", "gpt-4", "gemini-pro"],
confidence_threshold=0.8,
max_iterations=3,
arbiter_model="claude-3-opus-20240229"
)
result = await orchestrator.orchestrate("Your prompt")
print(f"Synthesized Response: {result['synthesis']['synthesis']}")
print(f"Confidence: {result['synthesis']['confidence']}")
print(f"Analysis: {result['synthesis']['analysis']}")
Architecture
The plugin uses a layered architecture:
- ConsortiumOrchestrator: Main orchestration layer
- DatabaseConnection: Singleton for database operations
- IterationContext: Manages iteration state and history
- Response Synthesis: Handled by arbiter model
- Logging System: Multi-level logging with file and console output
Core Algorithm Flow
The following Mermaid diagram illustrates the core algorithm flow of the LLM Karpathy Consortium:
flowchart TD
A[Start] --> B[Get Model Responses]
B --> C[Synthesize Responses]
C --> D{Check Confidence}
D -- Confidence >= Threshold --> E[Return Final Result]
D -- Confidence < Threshold --> F{Max Iterations Reached?}
F -- No --> G[Prepare Next Iteration]
G --> B
F -- Yes --> E
Development
To contribute:
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]" - Run tests:
pytest - Submit pull requests with tests and documentation
License
MIT License
Credits
Developed as part of the LLM ecosystem, inspired by Andrej Karpathy's work on model collaboration and iteration.
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
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 llm_consortium-0.2.tar.gz.
File metadata
- Download URL: llm_consortium-0.2.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f72a2f018e27d9aec02b0babbfb67e61a189819dcc9bda713a9fc369259f084e
|
|
| MD5 |
8b51abee00469f06c523e21b1a08fb6b
|
|
| BLAKE2b-256 |
683d655630188aedc0c64c0b6d81a56357cffe3902da4ea0114b3c6fb29e1d7d
|
File details
Details for the file llm_consortium-0.2-py3-none-any.whl.
File metadata
- Download URL: llm_consortium-0.2-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0825719ef521995838f74e441705e7fee17fc12020eecb8c7cb39eed7cd5bc9
|
|
| MD5 |
db5e5a3ff4b2822cdad662d72cdbe120
|
|
| BLAKE2b-256 |
7b89b758620d2eceeabb8486b69efa633fcaf1924cbde6d51721b88a3fa9e620
|