2.8 KiB
2.8 KiB
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
# 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 usesOPENAI_API_KEY. Create a.envfile in the project root:
OPENAI_API_KEY=sk-...
or export it directly:
export OPENAI_API_KEY="sk-..."
📦 Usage
The main entry point is solution.py.
1. Run with an inline string
python solution.py "Write a short report on LangChain and its applications."
Output
{
"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:
Develop a Python script that uses LangChain to parse user input and produce a structured task card.
Run:
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:
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
- Prompt – A
PromptTemplateinstructs the model to output JSON matching theTaskCardschema. - LLM –
ChatOpenAI(any OpenAI-compatible model) processes the prompt. - Parser –
PydanticOutputParservalidates and converts the raw text into aTaskCard. - Result – The script prints the JSON representation and a short human‑readable summary.
📄 License
MIT © 2026