feat: solution for 'Экзамен: Самокорректирующийся агент'

This commit is contained in:
2026-06-30 11:36:56 +03:00
parent 12db9ff18b
commit db2278e693
3 changed files with 153 additions and 42 deletions
+55 -41
View File
@@ -1,53 +1,67 @@
# Самокорректирующийся агент
# SelfCorrecting Agent Demo
## Описание проекта
Проект реализует самокорректирующийся агент, использующий **LangChain** и **OpenAI** для генерации и корректировки текста. Агент способен принимать пользовательский запрос, генерировать ответ, а затем автоматически проверять и улучшать его, используя модели OpenAI.
## Overview
## Технологический стек
- **Python 3.11+** – основной язык разработки
- **LangChain** – библиотека для построения цепочек LLM
- **OpenAI** API для доступа к GPT‑моделям
- **langchain-openai** адаптер LangChain для OpenAI (ключевая зависимость проекта)
This repository contains a minimal Python project that demonstrates a **selfcorrecting agent** using the OpenAI API.
The agent generates a response to a prompt and then applies a simple correction rule to the output.
## Technology Stack
| Component | Version | Notes |
|-----------|---------|-------|
| Python | 3.11+ | The code is written for Python 3.11. |
| OpenAI SDK | `openai>=1.0.0` | Required dependency for interacting with the OpenAI API. |
> **Mandatory Dependency**
> The assignment explicitly requires the `openai` package. It is listed in `requirements.txt` and will be installed with `pip install -r requirements.txt`.
## Setup
1. **Clone the repository**
```bash
git clone https://git.brojs.ru/kuzakhmetovartur/ekzamen-samokorrektiruyuschiysya-agent.git
cd ekzamen-samokorrektiruyuschiysya-agent
```
2. **Create a virtual environment** (recommended)
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\\Scripts\\activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Set your OpenAI API key**
```bash
export OPENAI_API_KEY="sk-..."
```
## Running the Demo
## Установка
```bash
# Клонируйте репозиторий
git clone https://git.brojs.ru/kuzakhmetovartur/ekzamen-samokorrektiruyuschiysya-agent.git
cd ekzamen-samokorrektiruyuschiysya-agent
# Создайте виртуальное окружение (рекомендуется)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Установите зависимости
pip install -r requirements.txt
python src/index.py
```
## Конфигурация
Создайте файл `.env` в корне проекта и добавьте ключ OpenAI:
```
OPENAI_API_KEY=sk-...
```
You should see two outputs: the raw response from the model and the corrected version.
## Запуск
```bash
python agent.py
```
(Файл `agent.py` содержит основной код агента.)
## Extending the Agent
## Документация
- **agent.py** – точка входа, реализует логику генерации и коррекции
- **utils.py** – вспомогательные функции
- **config.py** – конфигурация и параметры модели
The current correction logic is intentionally simple. To build a more sophisticated selfcorrecting agent:
## Как это работает
1. Пользователь вводит запрос.
2. Агент генерирует ответ с помощью модели GPT‑4.
3. Ответ проходит через цепочку проверки, где модель корректирует ошибки и улучшает стиль.
4. Итоговый ответ выводится пользователю.
- Replace the `correct_text` function with a rulebased or MLbased correction.
- Add unit tests in a `tests/` directory.
- Integrate with a larger application or chatbot framework.
## Лицензия
MIT License
## License
This project is provided as-is for educational purposes. Feel free to adapt and extend it.
---
*Если возникнут вопросы, обращайтесь к преподавателю.*
**Author:** Artur Kuzakhmetov
**Date:** 28.05.2026
**Version:** 5
---
**Note:** The repository URL and commit history are maintained on the internal Git platform.