Spaces:
Running
Running
File size: 1,481 Bytes
68b80a4 |
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 32 33 34 35 36 37 38 39 40 41 42 |
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)}" |