
回复
LLM-Reasoner 是一个库,它让任何 LLM(大模型)都能像 OpenAI o1 和 DeepSeek R1 一样深入思考。
✨ 主要特点
🧠 循序渐进的推理:不再有黑箱答案!准确了解 LLM 是如何思考的,类似于 O1 的系统方法
🔄 实时进度:通过流畅的动画观看推理的展开
🎯 多提供商支持:与 LiteLLM 支持的所有提供商兼容
🎮 精美的 UI:一个漂亮的 Streamlit 界面可供使用
🛠️ 高级用户 CLI:无缝嵌入你的代码
📊 信心跟踪:了解 LLM 对每个步骤的确定程度
首先安装:
pip install llm-reasoner
设置 OpenAI key:
export OPENAI_API_KEY="sk-your-key"
对于国内用户可以选择提供了与 OpenAI 接口兼容的模型或者是使用 llama_cpp_python 启动一个本地的 LLM 服务,这个服务接口与 OpenAI 接口兼容。
以下是一些简单的用法:
# 列当前所有可用模型
llm-reasoner models
# 生成一个推理链
llm-reasoner reason "How do planes fly?" --min-steps 5
#启动 UI 界面
llm-reasoner ui
或者直接在你的代码中使用:
from llm_reasoner import ReasonChain
import asyncio
async def main():
# Create a chain with your preferred settings
chain = ReasonChain(
model="gpt-4", # Choose your model
min_steps=3, # Minimum reasoning steps
temperature=0.2, # Control creativity
timeout=30.0 # Set your timeout
)
# Watch it think step by step!
async for step in chain.generate_with_metadata("Why is the sky blue?"):
print(f"\nStep {step.number}: {step.title}")
print(f"Thinking Time: {step.thinking_time:.2f}s")
print(f"Confidence: {step.confidence:.2f}")
print(step.content)
asyncio.run(main())
https://github.com/harishsg993010/LLM-Reasoner
本文转载自PyTorch研习社,作者:南七无名式