Spaces:
Running
Running
from .tool import Tool | |
from openai import OpenAI | |
from dotenv import load_dotenv | |
import os | |
load_dotenv("./.env") | |
class SummarizeTool(Tool): | |
def __init__(self): | |
super().__init__( | |
name="summarize", | |
description="Summarize the content of a URL", | |
inputSchema={ | |
"type": "object", | |
"properties": { | |
"content": {"type": "string", "description": "The content to summarize"} | |
} | |
} | |
) | |
api_key = os.environ.get("CEREBRAS_API_KEY") | |
if not api_key: | |
raise ValueError("Please set CEREBRAS_API_KEY environment variable") | |
self.client = OpenAI(base_url="https://api.cerebras.ai/v1", api_key=api_key) | |
def __call__(self, **kwargs): | |
try: | |
content = kwargs.get("content") | |
if not content: | |
return "Error: Content parameter is required" | |
response = self.client.chat.completions.create( | |
model="qwen-3-32b", | |
messages=[ | |
{"role": "system", "content": "You are a helpful assistant that summarizes content while keeping the all important information."}, | |
{"role": "user", "content": content} | |
] | |
) | |
return response.choices[0].message.content | |
except Exception as e: | |
return f"Error during summarization: {str(e)}" |