Metadata-Version: 2.1
Name: reasoning
Version: 0.1.0
Summary: A reasoning framework for all LLMs
Home-page: https://github.com/colesmcintosh/reasoning
License: MIT
Keywords: llm,ai,reasoning,framework,openai,anthropic
Author: colesmcintosh
Author-email: colemcintosh6@gmail.com
Requires-Python: >=3.9
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: anthropic (>=0.45.2,<0.46.0)
Requires-Dist: openai (>=1.61.0,<2.0.0)
Requires-Dist: pydantic (>=2.6.1,<3.0.0)
Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
Requires-Dist: requests (>=2.31.0,<3.0.0)
Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
Project-URL: Documentation, https://github.com/colesmcintosh/reasoning
Project-URL: Repository, https://github.com/colesmcintosh/reasoning
Description-Content-Type: text/markdown

# 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:

1. Initial reasoning and response generation
2. Verification and refinement of the response

## Installation

Basic installation:
```bash
pip install reasoning
```

With OpenAI support:
```bash
pip install "reasoning[openai]"
```

With Anthropic support:
```bash
pip install "reasoning[anthropic]"
```

With all supported APIs:
```bash
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:
```bash
export OPENAI_API_KEY='your-api-key'
export ANTHROPIC_API_KEY='your-api-key'
export OPENROUTER_API_KEY='your-api-key'
```

Or in Python:
```python
import os
os.environ['OPENAI_API_KEY'] = 'your-api-key'
```

## Quick Start

### Using OpenAI

```python
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

```python
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

```python
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

```python
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:

```python
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. 
