Spaces:
Sleeping
Sleeping
File size: 1,224 Bytes
f9e5853 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from crewai import Agent, Task
class SummarizerAgent(Agent):
def __init__(self, llm):
super().__init__(
llm=llm,
role="Content Summarizer",
backstory="I summarize research content into concise insights.",
goal="Summarize research articles or content to provide clear and precise information."
)
def execute_task(self, task: Task, context: dict = None, tools: list = None):
"""Execute the summarization task."""
if not context:
raise ValueError("Summarization task requires content in context.")
raw_content = context
if isinstance(raw_content, str):
summary = self.summarize(raw_content)
elif isinstance(raw_content, list) and all(isinstance(item, str) for item in raw_content):
summary = self.summarize("\n".join(raw_content))
else:
raise ValueError("Raw content must be a string or a list of strings.")
return summary
def summarize(self, content):
"""Summarize the content using the LLM."""
return self.llm.call([
{"role": "user", "content": content}
]) |