2.0 KiB
2.0 KiB
Assignment Card Extraction
This project demonstrates how to convert a natural language assignment description into a structured data object using LangChain and Pydantic.
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
-
Clone the repository (or copy the files into a directory):
git clone https://github.com/your-username/assignment-card-extractor.git cd assignment-card-extractor -
Create a virtual environment (recommended):
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt -
Configure the OpenAI API key:
- Open the
.envfile. - Replace
your_openai_api_key_herewith your actual key.
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXX - Open the
Running the Example
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.pyto use a different model or adjust temperature. - Add more fields: Update the
AssignmentCardmodel and the prompt template accordingly. - Use in a pipeline: Import the
chainobject fromsrc/main.pyinto your own application.
License
MIT License