feat: solution for 'Экзамен: Самокорректирующийся агент'
This commit is contained in:
@@ -1,84 +1,34 @@
|
||||
# Assignment Card Extraction
|
||||
# Экзамен: Самокорректирующийся агент
|
||||
|
||||
This project demonstrates how to convert a natural language assignment description into a structured data object using **LangChain** and **Pydantic**.
|
||||
Главная
|
||||
Мои задания
|
||||
Экзамен: Самокорректирующийся агент
|
||||
5Д
|
||||
EN
|
||||
Экзамен: Самокорректирующийся агент
|
||||
Зачёт
|
||||
Версия 1
|
||||
Дедлайн сдачи: 31.08.2026
|
||||
|
||||
## Features
|
||||
В работе
|
||||
|
||||
- Parses assignment details such as title, subject, deadline, deliverable type, and grading hints.
|
||||
- Uses OpenAI's GPT model to interpret free‑form text.
|
||||
- Validates the output with a Pydantic model to ensure type safety.
|
||||
Редактирование ответа
|
||||
|
||||
## Prerequisites
|
||||
Заполните ответ и отправьте работу на проверку преподавателю.
|
||||
|
||||
- Python 3.10 or newer
|
||||
- An OpenAI API key
|
||||
Тип ответа
|
||||
Текст
|
||||
Ссылка
|
||||
Файлы
|
||||
Текст ответа
|
||||
Прикреплённые файлы
|
||||
Загрузить файл
|
||||
Отправить на проверку
|
||||
Отменить
|
||||
|
||||
## Setup
|
||||
Задание
|
||||
|
||||
1. **Clone the repository** (or copy the files into a directory):
|
||||
Практическое задание: Самокорректирующийся агент
|
||||
Цель
|
||||
|
||||
```bash
|
||||
git clone https://github.com/your-username/assignment-card-extractor.git
|
||||
cd assignment-card-extractor
|
||||
```
|
||||
|
||||
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. **Configure the OpenAI API key**:
|
||||
|
||||
- Open the `.env` file.
|
||||
- Replace `your_openai_api_key_here` with your actual key.
|
||||
|
||||
```dotenv
|
||||
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXX
|
||||
```
|
||||
|
||||
## Running the Example
|
||||
|
||||
```bash
|
||||
python src/main.py
|
||||
```
|
||||
|
||||
You should see output similar to:
|
||||
|
||||
```
|
||||
=== Parsed Assignment Card ===
|
||||
{
|
||||
"title": "Мини-отчёт по LangChain",
|
||||
"subject": "LangChain",
|
||||
"deadline_hint": "к пятнице",
|
||||
"deliverable_type": "отчёт",
|
||||
"grading_hints": [
|
||||
"полнота",
|
||||
"пример кода"
|
||||
]
|
||||
}
|
||||
|
||||
=== Human-readable Summary ===
|
||||
Title: Мини-отчёт по LangChain
|
||||
Subject: LangChain
|
||||
Deadline: к пятнице
|
||||
Deliverable: отчёт
|
||||
Grading Hints: полнота, пример кода
|
||||
```
|
||||
|
||||
## Customization
|
||||
|
||||
- **Change the LLM**: Edit `src/main.py` to use a different model or adjust temperature.
|
||||
- **Add more fields**: Update the `AssignmentCard` model and the prompt template accordingly.
|
||||
- **Use in a pipeline**: Import the `chain` object from `src/main.py` into your own application.
|
||||
|
||||
## License
|
||||
|
||||
MIT License
|
||||
Реализовать LangGraph-агента, который после выполнения задачи проверяет результат (LLM-as-
|
||||
@@ -0,0 +1,9 @@
|
||||
from typing import TypedDict, Optional
|
||||
|
||||
class AgentState(TypedDict):
|
||||
task: str
|
||||
result: str
|
||||
attempts: int
|
||||
status: str # pending | success | failed | max_attempts
|
||||
error: Optional[str]
|
||||
max_attempts: int
|
||||
@@ -0,0 +1,12 @@
|
||||
import random
|
||||
|
||||
def unreliable_tool(task: str) -> str:
|
||||
"""
|
||||
Simulate a tool that fails 30% of the time.
|
||||
"""
|
||||
if random.random() < 0.3:
|
||||
raise ValueError("Tool failed due to random error.")
|
||||
# Simple implementation: if task contains arithmetic, compute it
|
||||
if "2+2" in task:
|
||||
return "4"
|
||||
return "unknown"
|
||||
Reference in New Issue
Block a user