Spaces:
Build error
Build error
Download agents/summarizer_agent.py from Samagra07/KnowledgeKeeper: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/Samagra07/KnowledgeKeeper/resolve/main/agents/summarizer_agent.py
- Command line
-
hf download hf://spaces/Samagra07/KnowledgeKeeper/agents/summarizer_agent.py
-
curl -L -o summarizer_agent.py https://huggingface.co/spaces/Samagra07/KnowledgeKeeper/resolve/main/agents/summarizer_agent.py
1.22 kB
| 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} | |
| ]) |