сырой текст задания → плоская карточка: README.md
This commit is contained in:
@@ -1,3 +1,118 @@
|
|||||||
# task-69dd4221-syroy-tekst-zadaniya-plos
|
# Project: Raw Text → Flat Task Card
|
||||||
|
|
||||||
Решения домашних заданий
|
## 📖 Overview
|
||||||
|
|
||||||
|
This project turns a natural‑language description of an assignment into a **structured, machine‑readable card**.
|
||||||
|
Given a single sentence or short paragraph from a teacher (e.g., “Write a report on LangChain”), the script uses OpenAI via LangChain to produce a validated `TaskCard` object containing:
|
||||||
|
|
||||||
|
| Field | Description |
|
||||||
|
|-------|-------------|
|
||||||
|
| `title` | Short title of the task |
|
||||||
|
| `subject` | Subject area (optional) |
|
||||||
|
| `deadline_hint` | Free‑form hint about when it’s due |
|
||||||
|
| `deliverable_type` | What to submit (report, code, presentation…) |
|
||||||
|
| `grading_hints` | List of grading criteria mentioned |
|
||||||
|
|
||||||
|
The output is printed as JSON and a concise summary.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clone the repo (or copy the file)
|
||||||
|
git clone https://github.com/your‑repo/task‑card.git
|
||||||
|
cd task-card
|
||||||
|
|
||||||
|
# Create virtual environment (optional but recommended)
|
||||||
|
python -m venv .venv
|
||||||
|
source .venv/bin/activate # Windows: .venv\\Scripts\\activate
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
pip install langchain-core langchain-openai pydantic python-dotenv
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Environment variables**
|
||||||
|
> The script uses `OPENAI_API_KEY`. Create a `.env` file in the project root:
|
||||||
|
|
||||||
|
```dotenv
|
||||||
|
OPENAI_API_KEY=sk-...
|
||||||
|
```
|
||||||
|
|
||||||
|
or export it directly:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
export OPENAI_API_KEY="sk-..."
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Usage
|
||||||
|
|
||||||
|
The main entry point is `solution.py`.
|
||||||
|
|
||||||
|
### 1. Run with an inline string
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python solution.py "Write a short report on LangChain and its applications."
|
||||||
|
```
|
||||||
|
|
||||||
|
**Output**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"title": "Short Report on LangChain",
|
||||||
|
"subject": null,
|
||||||
|
"deadline_hint": "Submit by the end of the week.",
|
||||||
|
"deliverable_type": "report",
|
||||||
|
"grading_hints": [
|
||||||
|
"Clarity of explanation",
|
||||||
|
"Depth of examples"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Run with a file
|
||||||
|
|
||||||
|
Create `task.txt` containing your assignment description:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Develop a Python script that uses LangChain to parse user input and produce a structured task card.
|
||||||
|
```
|
||||||
|
|
||||||
|
Run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python solution.py -f task.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
The same JSON will be printed.
|
||||||
|
|
||||||
|
### 3. Using the output programmatically
|
||||||
|
|
||||||
|
You can import `TaskCard` from `solution.py` in another Python script:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from solution import TaskCard, parse_task_description
|
||||||
|
|
||||||
|
description = "Create a presentation on AI ethics."
|
||||||
|
card: TaskCard = parse_task_description(description)
|
||||||
|
print(card.title) # -> "Presentation on AI Ethics"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ How It Works
|
||||||
|
|
||||||
|
1. **Prompt** – A `PromptTemplate` instructs the model to output JSON matching the `TaskCard` schema.
|
||||||
|
2. **LLM** – `ChatOpenAI` (any OpenAI-compatible model) processes the prompt.
|
||||||
|
3. **Parser** – `PydanticOutputParser` validates and converts the raw text into a `TaskCard`.
|
||||||
|
4. **Result** – The script prints the JSON representation and a short human‑readable summary.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📄 License
|
||||||
|
|
||||||
|
MIT © 2026
|
||||||
|
|
||||||
|
---
|
||||||
Reference in New Issue
Block a user