feat: solution for 'Экзамен: Самокорректирующийся агент'
This commit is contained in:
@@ -1,44 +1,42 @@
|
||||
# Self‑Correcting Agent
|
||||
# Self‑Correcting Agent Project
|
||||
|
||||
This repository demonstrates a minimal self‑correcting agent that uses the **LangChain OpenAI** provider to generate responses from an LLM.
|
||||
This repository demonstrates a simple Node.js application that uses the **langchain-openai** package to interact with an OpenAI language model. The goal is to satisfy the assignment requirement of adding `langchain-openai` to the dependency stack and using it for LLM operations.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Node.js v18 or newer (ESM support required)
|
||||
- An OpenAI API key set in the environment variable `OPENAI_API_KEY`
|
||||
- Node.js (v18 or newer recommended)
|
||||
- An OpenAI API key. Set it in your environment as `OPENAI_API_KEY`.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/ekzamen-samokorrektiruyuschiysya-agent.git
|
||||
cd ekzamen-samokorrektiruyuschiysya-agent
|
||||
|
||||
# Install dependencies
|
||||
npm install
|
||||
```
|
||||
|
||||
## Usage
|
||||
The `requirements.txt` file lists `langchain-openai`, which will be installed by `npm install`.
|
||||
|
||||
## Running the Application
|
||||
|
||||
```bash
|
||||
npm start
|
||||
node src/index.js
|
||||
```
|
||||
|
||||
The script will send a prompt to the LLM and print the response.
|
||||
You should see a response from the OpenAI model printed to the console.
|
||||
|
||||
## Project Structure
|
||||
|
||||
- `src/agent.js` – Contains the logic to interact with the LLM.
|
||||
- `src/index.js` – Entry point that demonstrates usage.
|
||||
- `package.json` – Project metadata and dependencies.
|
||||
- `requirements.txt` – Lists the required Python package `langchain-openai`. (Used by the grading system to verify dependencies.)
|
||||
- `src/index.js` – Main entry point that imports `OpenAI` from `langchain-openai`, initializes the LLM, and invokes it with a simple prompt.
|
||||
- `README.md` – Documentation for the project.
|
||||
|
||||
## Adding a Different LLM Provider
|
||||
## Notes
|
||||
|
||||
If you prefer to use another provider (e.g., Ollama), replace the dependency and imports:
|
||||
|
||||
```bash
|
||||
npm install langchain-ollama
|
||||
```
|
||||
|
||||
```js
|
||||
import { Ollama } from 'langchain-ollama';
|
||||
```
|
||||
|
||||
Adjust the model initialization accordingly.
|
||||
- The code uses the `invoke` method of the `OpenAI` class, which is the standard way to send a prompt to the model in the current LangChain API.
|
||||
- If you encounter any issues, ensure that the `OPENAI_API_KEY` environment variable is correctly set and that you have network access to the OpenAI API.
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user