From 099e1069f9830c6cd463bc7487d99470da1bbb9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B4=D0=B5=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A1=D0=B0?= =?UTF-8?q?=D1=82=D1=82=D0=B0=D1=80=D0=BE=D0=B2=D0=B0?= Date: Tue, 2 Jun 2026 06:27:31 +0000 Subject: [PATCH] Add main.py --- main.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..3fc3f97 --- /dev/null +++ b/main.py @@ -0,0 +1,36 @@ +from langchain_core.prompts import ChatPromptTemplate +from langchain_openai import ChatOpenAI +from pydantic import BaseModel, Field +from typing import List + +class TaskCard(BaseModel): + title: str = Field(..., description="Task title") + subject: str | None = Field(None, description="Subject or topic of the task") + deadline_hint: str | None = Field(None, description="Short hint about deadline") + deliverable_type: str | None = Field(None, description="Type of deliverable (e.g., code, report)") + grading_hints: List[str] | None = Field(None, description="Hints for grading") + +prompt_template = ChatPromptTemplate.from_messages([ + ( + "system", + "You are an assistant that extracts structured task information from a raw text. Return JSON matching the TaskCard schema.", + ), + ("human", "{raw_text}"), +]) + +llm = ChatOpenAI(model="gpt-4o-mini", temperature=0) + +async def parse_task(raw_text: str) -> TaskCard: + chain = prompt_template | llm.with_structured_output(TaskCard) + result = await chain.ainvoke({"raw_text": raw_text}) + return result + +if __name__ == "__main__": + import sys, json + if len(sys.argv) < 2: + print("Usage: python main.py ") + sys.exit(1) + with open(sys.argv[1], "r", encoding="utf-8") as f: + raw = f.read() + card = asyncio.run(parse_task(raw)) + print(json.dumps(card.model_dump(), indent=2))