feat: solution for 'Повторный экзамен: Граф с рефлексией и доработкой'

This commit is contained in:
2026-07-01 15:43:46 +03:00
parent 6283334f30
commit e756e363b2
6 changed files with 279 additions and 47 deletions
+73 -8
View File
@@ -1,15 +1,80 @@
# Самокорректирующийся агент
# Graph Reflection and Refinement Demo
This repository contains a simple implementation of a selfcorrecting agent using LangChain.
The project requires the following Python packages:
This repository demonstrates how to integrate **LangChain LLMs** (OpenAI or Ollama) into a simple Python script that explains graph theory concepts. The project is intentionally minimal to focus on the LLM integration.
- `langchain-core` core LangChain functionality.
- `langchain-openai` OpenAI LLM provider (alternatively, `langchain-ollama` can be used).
## Features
Install the dependencies with:
- **OpenAI LLM** support via `langchain-openai`.
- **Ollama LLM** support via `langchain-ollama`.
- Environment variable configuration using `.env` or system variables.
- Simple prompt chain that explains graph reflection and refinement.
## Setup
1. **Clone the repository**
```bash
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-graf-s-refleksiey-i-do
cd povtornyy-ekzamen-graf-s-refleksiey-i-do
```
2. **Create a virtual environment (recommended)**
```bash
python3 -m venv .venv
source .venv/bin/activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Configure environment variables**
Create a `.env` file in the project root (or set system variables) with one of the following:
```dotenv
# For OpenAI
OPENAI_API_KEY=your_openai_api_key
OPENAI_MODEL=gpt-3.5-turbo
OPENAI_TEMPERATURE=0.7
# OR for Ollama
OLLAMA_HOST=http://localhost:11434
OLLAMA_MODEL=llama2
OLLAMA_TEMPERATURE=0.7
```
Only one of the two configurations is required.
## Usage
Run the script:
```bash
pip install -r requirements.txt
python src/main.py
```
Feel free to extend the agent with additional tools or prompts as needed.
You should see an LLM-generated explanation of graph reflection and refinement printed to the console.
## Project Structure
```
povtornyy-ekzamen-graf-s-refleksiey-i-do/
├── src/
│ └── main.py # Core script with LangChain integration
├── requirements.txt # All required Python packages
└── README.md # Project documentation
```
## Notes
- The script automatically selects the LLM based on the presence of environment variables.
- If neither `OPENAI_API_KEY` nor `OLLAMA_HOST` is set, the script will raise an error.
- Feel free to extend the prompt or chain logic to suit more complex use cases.
---
Happy coding!