Reasoning Framework
A Python package that adds R1-style reasoning capabilities to any Language Model (LLM). This framework enables step-by-step reasoning and verification of responses using a two-step process:
- Initial reasoning and response generation
- Verification and refinement of the response
Installation
Basic installation:
pip install reasoning
With OpenAI support:
pip install "reasoning[openai]"
With Anthropic support:
pip install "reasoning[anthropic]"
With all supported APIs:
pip install "reasoning[openai,anthropic]"
Environment Variables
Depending on which API you're using, you'll need to set the appropriate environment variables:
- For OpenAI:
OPENAI_API_KEY - For Anthropic:
ANTHROPIC_API_KEY - For OpenRouter:
OPENROUTER_API_KEY
You can set these in your shell:
export OPENAI_API_KEY='your-api-key'
export ANTHROPIC_API_KEY='your-api-key'
export OPENROUTER_API_KEY='your-api-key'
Or in Python:
import os
os.environ['OPENAI_API_KEY'] = 'your-api-key'
Quick Start
Using OpenAI
from reasoning import ReasoningFramework
from reasoning.examples.openai_example import create_openai_call
# Create model-specific callers
gpt4_call = create_openai_call("gpt-4")
gpt35_call = create_openai_call("gpt-3.5-turbo")
# Initialize the framework
framework = ReasoningFramework(
reasoning_llm_call=gpt4_call,
verification_llm_call=gpt35_call
)
# Process a question
response = framework.process(
"What would be the implications of achieving AGI?",
reasoning_kwargs={"temperature": 0.7},
verification_kwargs={"temperature": 0.5}
)
print("Original Message:", response.message)
print("\nReasoning Process:", response.reasoning)
print("\nInitial Response:", response.initial_response)
print("\nVerified Response:", response.final_response)
Using Anthropic
from reasoning import ReasoningFramework
from reasoning.examples.anthropic_example import create_anthropic_call
# Create model-specific callers
sonnet_call = create_anthropic_call("claude-3-sonnet")
opus_call = create_anthropic_call("claude-3-opus")
# Initialize the framework
framework = ReasoningFramework(
reasoning_llm_call=sonnet_call,
verification_llm_call=opus_call
)
# Process a question
response = framework.process(
"What would be the implications of achieving AGI?",
reasoning_kwargs={"temperature": 0.7},
verification_kwargs={"temperature": 0.5}
)
Using OpenRouter
from reasoning import ReasoningFramework
from reasoning.examples.openrouter_example import create_openrouter_call
# Create model-specific callers
r1_call = create_openrouter_call("deepseek/deepseek-r1")
claude_call = create_openrouter_call("anthropic/claude-3-sonnet")
# Initialize the framework
framework = ReasoningFramework(
reasoning_llm_call=r1_call,
verification_llm_call=claude_call
)
# Process a question
response = framework.process(
"What would be the implications of achieving AGI?",
reasoning_kwargs={"temperature": 0.7},
verification_kwargs={"temperature": 0.5}
)
Features
- Flexible integration with any LLM through callback functions
- Built-in support for OpenAI, Anthropic, and OpenRouter APIs
- Structured reasoning process with verification
- Customizable system prompts for both reasoning and verification
- Type-safe implementation using Pydantic models
- Comprehensive logging for debugging
Advanced Usage
Custom System Prompts
framework = ReasoningFramework(
reasoning_llm_call=my_llm_call,
verification_llm_call=my_verification_call,
reasoning_system_prompt="You are an expert at breaking down complex problems...",
verification_system_prompt="You are a critical thinker who verifies conclusions..."
)
Error Handling
The framework includes built-in error handling and logging:
import logging
logging.basicConfig(level=logging.DEBUG) # Set to see detailed logs
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for reasoning 0.1.0
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 |
|---|---|---|---|---|
| reasoning-0.1.0.tar.gz | 6.8 kB | Without provenance | Details for reasoning-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| reasoning-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for reasoning-0.1.0-py3-none-any.whl |
Total release size: 15.5 kB
Release files / reasoning-0.1.0.tar.gz
| Download URL | reasoning-0.1.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5fb470d223d91dcb494c5b881a17e82296fbd0b292a77962358c6ae220b6e624
|
|
BLAKE2b-256 checksum How to use checksums |
fc244b4b70d2c1617271a092a9ad3e0ffacfbbe5b13fdf3d7e75f45d977ca304
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.13.1 Darwin/23.0.0
|
Release files / reasoning-0.1.0-py3-none-any.whl
| Download URL | reasoning-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d563685b36888cce0b608e505bf79310916fa977afac523b59f23ee4d8c12f6a
|
|
BLAKE2b-256 checksum How to use checksums |
466789b0b972d978e1e0c759abbe203f4671cb4f357d3a0cef3e96419b0bb65b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.13.1 Darwin/23.0.0
|
Security for reasoning 0.1.0
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.