Skip to main content

Advanced reasoning chains with multiple LLM providers

Project description

🤔 LLM-Reasoner

Transform any LLM into a methodical thinker that excels at systematic reasoning, featuring:

  • Support for multiple LLM providers through LiteLLM
  • Structured reasoning with confidence scores and self-reflection
  • Command-line interface for quick reasoning tasks
  • Interactive Streamlit UI for visual exploration
  • Easy integration with existing Python applications
  • Automated self-reflection and quality scoring
  • Support for mathematical notation using LaTeX
  • Methodical step-by-step problem solving

🚀 Getting Started

Install LLM-Reasoner with pip:

pip install llm-reasoner

Configure your API keys:

# Using OpenAI? Pop this in:
export OPENAI_API_KEY="your-key"

# Team Google? Here you go:
export VERTEX_PROJECT="your-project"
export VERTEX_LOCATION="your-location"

# Claude fan? Got you covered:
export ANTHROPIC_API_KEY="your-key"

🎮 Quick Play

Try these commands to get started:

# Check out what models you can use
llm-reasoner models

# Ask it something cool
llm-reasoner reason "Why do planes stay up in the air?"

# Want a nice UI to play with?
llm-reasoner ui

🛠️ Using It In Your Code

Here's the simplest way to use LLM-Reasoner:

from reasonchain import ReasonChain
import asyncio

async def main():
    chain = ReasonChain()
    async for step in chain.generate("How does evolution work?"):
        print(f"🤔 Step {step.number}: {step.title}")
        print(step.content)

asyncio.run(main())

Want more control? Here's an advanced example:

chain = ReasonChain(
    model="gpt-4",                         # Pick your favorite model
    max_tokens=1000,                       # Let it think deeper
    temperature=0.3,                       # Control creativity
    prompt_template="Let's explore: {prompt}"  # Make it your own
)

# Get all the details about its thinking process
async for step in chain.generate_with_metadata("How do computers learn?"):
    print(f"💭 Step {step.number}: {step.title}")
    print(f"🎯 Confidence: {step.confidence}") 
    print(f"⏱️ Thinking time: {step.thinking_time}s")
    print(step.content)

🔧 Custom Models

You can register custom models with LLM-Reasoner using the model registry:

from reasonchain import model_registry

# Register a custom model
model_registry.register_model(
    name="my-custom-model",
    provider="custom-provider",
    context_window=4096  # Optional
)

# Use your custom model
chain = ReasonChain(model="my-custom-model")

This allows you to use any LLM provider supported by LiteLLM, not just the default providers. See LiteLLM's documentation for the full list of supported providers.

🌟 Features in Detail

Each reasoning step includes:

  • Step number (keeping things organized)
  • Clear title (what it's pondering)
  • Detailed thoughts (the good stuff)
  • Confidence score (how sure it is)
  • Thinking time (we track speed too!)
  • Timestamp (when each thought happened)
  • Next action (what it's planning)

🎨 Interactive UI

Launch the visual interface with:

llm-reasoner ui

The UI provides:

  • Model selection
  • Parameter adjustment
  • Real-time reasoning visualization
  • Interactive exploration

Development

To contribute to LLM-Reasoner:

  1. Clone the repository
  2. Install development dependencies: pip install -e ".[dev]"
  3. Run tests: pytest

🤝 Contributing

Found a bug or have ideas? We'd love to hear from you:

📜 License

MIT License - See LICENSE file for details.


Made with ❤️ for those who believe AI should show its work! ✍️

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_reasoner-0.1.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file llm_reasoner-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llm_reasoner-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for llm_reasoner-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b23335979940f3ece004acbd96de50913f5e4fb03544c074df14d59d0c3aa842
MD5 8ef41b5213c7a5b0443e77df0948df5e
BLAKE2b-256 7874e22e8f8ddecf54303edefd6be81c94a254310e0f7c7edeed3639da59ee08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page