68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
import os
|
|
import json
|
|
from dotenv import load_dotenv
|
|
from models import TaskCard
|
|
from parser import TaskParser
|
|
|
|
load_dotenv()
|
|
|
|
# Example raw task descriptions
|
|
EXAMPLES = [
|
|
"Write a mini-report on LangChain for Friday, 3-5 pages, include code examples",
|
|
"Build a LangGraph agent with memory and interrupts, push code to github by Monday",
|
|
"Implement a REST API with FastAPI and JWT auth, add unit tests, deadline in 1 week",
|
|
"Create a RAG pipeline using Qdrant vector store and OpenAI embeddings",
|
|
"Build a chat bot with multi-turn memory using LangChain ConversationBufferMemory",
|
|
]
|
|
|
|
def demo_single(parser: TaskParser, text: str, idx: int) -> TaskCard:
|
|
"""Parse one example and print result."""
|
|
print(f"\n=== Example {idx} ===")
|
|
print(f"Raw: {text[:80]}")
|
|
card = parser.parse(text)
|
|
print(card.to_markdown())
|
|
return card
|
|
|
|
def demo_batch(parser: TaskParser, texts: list) -> list:
|
|
"""Parse a batch of texts and save as JSON."""
|
|
print("\n=== Batch parse ===")
|
|
cards = parser.batch_parse(texts)
|
|
for i, card in enumerate(cards):
|
|
fname = f"card_{i+1}.json"
|
|
with open(fname, "w", encoding="utf-8") as f:
|
|
json.dump(card.model_dump(), f, ensure_ascii=False, indent=2)
|
|
print(f" Saved {fname}: {card.title}")
|
|
return cards
|
|
|
|
def demo_format(card: TaskCard) -> None:
|
|
"""Demonstrate different output formats."""
|
|
print("\n=== Formats ===")
|
|
print("Markdown:")
|
|
print(card.to_markdown())
|
|
print("\nJSON:")
|
|
print(json.dumps(card.model_dump(), ensure_ascii=False, indent=2))
|
|
|
|
def main() -> None:
|
|
"""Run all demos."""
|
|
parser = TaskParser()
|
|
|
|
# Demo 1: single parse
|
|
card1 = demo_single(parser, EXAMPLES[0], 1)
|
|
|
|
# Demo 2: another single parse
|
|
demo_single(parser, EXAMPLES[1], 2)
|
|
|
|
# Demo 3: third single parse
|
|
demo_single(parser, EXAMPLES[2], 3)
|
|
|
|
# Demo 4: batch parse all examples
|
|
demo_batch(parser, EXAMPLES)
|
|
|
|
# Demo 5: show formats
|
|
demo_format(card1)
|
|
|
|
print("\nDone!")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|