reasoning 0.1.0
A reasoning framework for all LLMs
License: MIT
Requires Python: >=3.9
Keywords: llm, ai, reasoning, framework, openai, anthropic

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