smolagent_practice / tools /summarize_topic.py
Justchidi's picture
Upload agent
6f4a389 verified
Raw History Blame Contribute Delete
914 Bytes
from smolagents import Tool
from typing import Any, Optional
class SimpleTool(Tool):
name = "summarize_topic"
description = "This agent uses a web search tool to getch search results for the provided topic and the summarizes them and\nreturns the summary"
inputs = {"topic":{"type":"string","description":"The topic to provide summary for"}}
output_type = "string"
def forward(self, topic: str) -> str:
"""
This agent uses a web search tool to getch search results for the provided topic and the summarizes them and
returns the summary
Args:
topic: The topic to provide summary for
"""
from transformers import pipeline
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
summary = summarizer(topic, max_length=100, min_length=30, do_sample=False)
return summary[0]['summary_text']