Project: Raw Text → Flat Task Card

📖 Overview

This project turns a naturallanguage description of an assignment into a structured, machinereadable 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 Freeform hint about when its 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/yourrepo/taskcard.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:

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

  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 humanreadable summary.

📄 License

MIT © 2026


S
Description
Решения домашних заданий
Readme 29 KiB
Languages
Python 100%