| """Text summarization tool.""" |
|
|
| from langchain_core.tools import tool |
|
|
|
|
| @tool |
| def summarize_text(text: str, max_sentences: int = 3) -> str: |
| """ |
| Summarize the given text into a concise summary. |
| |
| This tool takes a longer text and creates a brief summary by extracting |
| the most important sentences or creating a condensed version. |
| |
| Args: |
| text: The text to summarize |
| max_sentences: Maximum number of sentences in the summary (default: 3) |
| |
| Returns: |
| A concise summary of the input text |
| """ |
| |
| |
| sentences = [s.strip() for s in text.split('.') if s.strip()] |
| |
| if len(sentences) <= max_sentences: |
| return text |
| |
| |
| summary_sentences = sentences[:max_sentences] |
| summary = '. '.join(summary_sentences) |
| |
| |
| if len(sentences) > max_sentences: |
| summary += '...' |
| |
| return summary |
|
|
| |
|
|