This project provides an API that leverages large language models (LLMs) to perform complex reasoning tasks through a unique step-by-step approach. It uses a feedback-driven system to ensure accuracy and logical consistency. The API is built with FastAPI and is compatible with OpenAI's chat completion endpoint.
- Step-by-Step Reasoning: Breaks down complex problems into smaller, manageable steps.
- Feedback Mechanism: Integrates a rewarder model that provides feedback on each step, ensuring correctness.
- Logical/Analytical and Creative Task Handling: Adapts the problem-solving strategy based on the nature of the task.
- OpenAI Compatibility: Designed to work with models compatible with the OpenAI API interface.
- Streaming Support: Offers streaming responses for real-time interaction.
The core of the system is based on two main components:
- Reasoning Agent: This component generates the step-by-step solution based on the provided prompt and system instructions.
- Rewarder Agent: This component evaluates each step generated by the reasoning agent and provides feedback.
The system iteratively generates and evaluates steps until a complete and correct solution is reached.
The SYS_MSG
defines the framework for problem-solving. It outlines the process for both logical/analytical and creative tasks.
For Logical/Analytical Tasks:
- Problem Decomposition: Clearly state the problem, list given information, constraints, missing information, and the expected output format.
- Component Analysis: Analyze primary, secondary, and implicit components, including their properties and dependencies.
- Relationship Mapping: Define direct, indirect, hierarchical, causal, and temporal relationships between components.
- Comprehension Levels: Understand the problem at literal, contextual, and abstract levels.
- Solution Development: List assumptions, detail solution steps with validation points, and define boundary conditions.
- Solution Verification: Ensure logical consistency, completeness, handle edge cases, and check for contradictions.
For Creative Tasks:
- Focus on originality and innovation.
- Provide clear reasoning for creative choices.
The REWARDER
message defines the role of the rewarder agent, which is to critically rate each step provided by the user. The rewarder only responds with one of three options:
- Correct: If the step is logically sound.
- Wrong: If the step contains an error.
- Too much information in one step. Split this up into smaller parts and think again: If the step contains multiple facts or ideas that should be separated.
- Python 3.9+
- An OpenAI-compatible API endpoint (e.g., a self-hosted LLM with an OpenAI-compatible interface).
- An API key for your LLM provider.
Set environment variables:
Create a `.env` file in the project root directory and add the following:
```
OAI_BASE_URL=<your_openai_compatible_api_base_url>
OAI_KEY=<your_api_key>
LLM_NAME=<your_model_name>
```
Replace the placeholders with your actual API base URL, API key, and the name of the LLM you want to use.
-
Start the FastAPI server using uvicorn:
uvicorn app:app --reload
This will start the API server on
http://0.0.0.0:8000
.