Spaces:
Paused
Paused
Download agents/summarizer.py from 3SCError404/miracle: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/spaces/3SCError404/miracle/resolve/main/agents/summarizer.py
- Command line
-
hf download hf://spaces/3SCError404/miracle/agents/summarizer.py
-
curl -L -o summarizer.py https://huggingface.co/spaces/3SCError404/miracle/resolve/main/agents/summarizer.py
1.08 kB
| from typing import Any, Dict, List | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from core.llm import get_llm | |
| SUMMARIZER_PROMPT = """ | |
| Summarize the following support ticket thread into a concise overview. | |
| Include: | |
| 1. The main problem or request. | |
| 2. Key actions taken so far. | |
| 3. Current status or pending items. | |
| Ticket Title: {title} | |
| Original Description: {description} | |
| Thread Messages: | |
| {messages} | |
| Summary: | |
| """ | |
| async def summarize_thread(title: str, description: str, messages: List[Dict[str, Any]]) -> str: | |
| """ | |
| Stand-alone utility to summarize a ticket thread. | |
| """ | |
| llm = get_llm() | |
| # Format messages for prompt | |
| formatted_messages = "\n".join([ | |
| f"- {m.get('sender_name', 'User')}: {m.get('content')}" | |
| for m in messages | |
| ]) | |
| prompt = ChatPromptTemplate.from_template(SUMMARIZER_PROMPT) | |
| chain = prompt | llm | |
| response = await chain.ainvoke({ | |
| "title": title, | |
| "description": description, | |
| "messages": formatted_messages or "No messages yet." | |
| }) | |
| return response.content | |