feat: solution for 'Экзамен: Самокорректирующийся агент'
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2026 Artur Kuzakhmetov
|
Copyright (c) 2026 Your Name
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the “Software”), to deal
|
of this software and associated documentation files (the “Software”), to deal
|
||||||
@@ -9,4 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
[Full MIT license text omitted for brevity]
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
@@ -1,37 +1,69 @@
|
|||||||
# Graph Reflexivity Project
|
# Самокорректирующийся агент
|
||||||
|
|
||||||
This project demonstrates a simple graph implementation in JavaScript that supports reflexivity (adding self-loops to all nodes). It uses the `graphlib` library for graph data structures and `lodash` for utility functions.
|
## Описание
|
||||||
|
|
||||||
## Installation
|
Данный проект реализует простого **самокорректирующегося агента** на Node.js. Агент генерирует ответ на заданный вопрос, а затем использует API OpenAI для проверки и улучшения своего ответа. Это демонстрационный пример того, как можно интегрировать модель GPT в цикл самокоррекции.
|
||||||
|
|
||||||
|
## Требования
|
||||||
|
|
||||||
|
- Node.js версии 18+ (рекомендуется LTS)
|
||||||
|
- npm (или yarn)
|
||||||
|
- **Пакеты, необходимые для работы проекта:**
|
||||||
|
- `dotenv` – для загрузки переменных окружения из файла `.env`
|
||||||
|
- `openai` – официальный клиент OpenAI для взаимодействия с API
|
||||||
|
- `jest` – для запуска тестов (только в режиме разработки)
|
||||||
|
|
||||||
|
## Установка
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# Клонируйте репозиторий
|
||||||
|
git clone https://git.brojs.ru/kuzakhmetovartur/ekzamen-samokorrektiruyuschiysya-agent.git
|
||||||
|
cd ekzamen-samokorrektiruyuschiysya-agent
|
||||||
|
|
||||||
|
# Установите зависимости
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
## Running the Example
|
## Конфигурация
|
||||||
|
|
||||||
```bash
|
Создайте файл `.env` в корне проекта и добавьте ваш ключ API OpenAI:
|
||||||
node src/index.js
|
|
||||||
|
```dotenv
|
||||||
|
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||||
```
|
```
|
||||||
|
|
||||||
You will see the adjacency list before and after applying reflexivity.
|
> ⚠️ **Важно**: Никогда не публикуйте ваш ключ API в публичных репозиториях.
|
||||||
|
|
||||||
## Testing
|
## Использование
|
||||||
|
|
||||||
Run the test suite with:
|
Запустите скрипт:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
Пример вывода:
|
||||||
|
|
||||||
|
```
|
||||||
|
Вопрос: Какой язык программирования лучше всего подходит для веб-разработки?
|
||||||
|
Ответ: JavaScript является популярным выбором для веб-разработки благодаря своей гибкости и широкому сообществу.
|
||||||
|
Самокоррекция: После проверки, ответ можно уточнить: JavaScript, особенно в сочетании с фреймворками вроде React или Vue, обеспечивает быстрый и интерактивный пользовательский интерфейс.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Тесты
|
||||||
|
|
||||||
|
Для запуска тестов используйте:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm test
|
npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
The tests cover basic graph operations, reflexivity, and adjacency list generation.
|
Тесты находятся в папке `__tests__` и проверяют базовую работу агента.
|
||||||
|
|
||||||
## Dependencies
|
## Лицензия
|
||||||
|
|
||||||
- **graphlib** – Provides the underlying graph data structure.
|
MIT © 2026
|
||||||
- **lodash** – Utility library (used for potential future extensions).
|
|
||||||
- **jest** – Testing framework (dev dependency).
|
|
||||||
|
|
||||||
## License
|
---
|
||||||
|
|
||||||
MIT
|
> **Примечание**: Этот проект создан в рамках экзамена по теме «Самокорректирующийся агент» и служит демонстрацией базовой реализации. Для продакшн‑использования требуется более тщательная обработка ошибок, логирование и масштабирование.
|
||||||
+14
-6
@@ -1,15 +1,23 @@
|
|||||||
{
|
{
|
||||||
"name": "graph-reflexivity",
|
"name": "self-correcting-agent",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "A simple graph implementation with reflexivity support",
|
"description": "A simple Node.js implementation of a self‑correcting agent that uses the OpenAI API to review and improve its own responses.",
|
||||||
"main": "src/index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
|
"keywords": [
|
||||||
|
"openai",
|
||||||
|
"self-correcting",
|
||||||
|
"agent",
|
||||||
|
"nodejs"
|
||||||
|
],
|
||||||
|
"author": "Your Name",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"graphlib": "^2.1.8",
|
"dotenv": "^16.4.5",
|
||||||
"lodash": "^4.17.21"
|
"openai": "^4.20.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^29.7.0"
|
"jest": "^29.7.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user