citationEdge / tools /function_tools /summarize_tool.py
omkarkudalkar222's picture
Fresh deployment without history
0e38162
Raw
History Blame Contribute Delete
1.14 kB
"""
Summarization tool: calls LLM to produce a concise summary of any text block.
"""
from tools.base_tool import BaseTool, ToolResult
from services.llm_service import LLMService
from utils.logger import get_logger
logger = get_logger("summarize_tool")
SYSTEM = (
"You are a precise scientific summarizer. "
"Return a concise, factual summary in 3-5 sentences. "
"Preserve key findings, methods, and numbers."
)
class SummarizeTool(BaseTool):
name = "summarize"
description = "Produce a concise LLM summary of a given text block."
def __init__(self, llm: LLMService):
self.llm = llm
async def run(self, text: str, max_words: int = 150) -> ToolResult:
if not text or not text.strip():
return self._err("Empty text provided to summarize tool.")
prompt = f"Summarize the following text in at most {max_words} words:\n\n{text}"
try:
summary = await self.llm.complete(SYSTEM, prompt)
return self._ok(summary.strip())
except Exception as e:
logger.error(f"Summarize tool failed: {e}")
return self._err(str(e))