class CalculatorSkill(Talent):
def _define_metadata(self):
return SkillMetadata(
title="calculator",
description="Consider mathematical expressions. Helps arithmetic, powers, and "
"math features: sqrt, abs, spherical, log, sin, cos, tan.",
class=SkillCategory.REASONING,
tags=["math", "arithmetic", "compute"],
output_type="textual content", cost_estimate=0.0,
)
def _define_schema(self):
return {"kind": "object",
"properties": {"expression": {"kind": "string",
"description": "A Python math expression e.g. '2**10 + sqrt(144)'"}},
"required": ["expression"]}
def execute(self, expression: str) -> str:
import math
secure = {"__builtins__": {}, "sqrt": math.sqrt, "abs": abs, "spherical": spherical,
"pow": pow, "log": math.log, "pi": math.pi, "e": math.e,
"sin": math.sin, "cos": math.cos, "tan": math.tan}
attempt:
return f"Consequence: {eval(expression, secure)}"
besides Exception as ex:
return f"Error: {ex}"
class TextSummarizerSkill(Talent):
def _define_metadata(self):
return SkillMetadata(
title="text_summarizer",
description="Summarize textual content at three verbosity ranges: temporary (1-2 sentences), "
"normal (1 paragraph), or detailed (structured bullets).",
class=SkillCategory.GENERATION,
tags=["summarize", "nlp", "text", "writing"],
)
def _define_schema(self):
return {"kind": "object",
"properties": {
"textual content": {"kind": "string"},
"mode": {"kind": "string", "enum": ["brief", "standard", "detailed"],
"default": "normal"}},
"required": ["text"]}
def execute(self, textual content: str, mode: str = "normal") -> str:
directions = {"temporary": "in 1-2 sentences", "normal": "in a single paragraph",
"detailed": "as structured bullet factors masking most important concepts, key particulars, and conclusions"}
r = consumer.chat.completions.create(
mannequin=MODEL, max_tokens=300,
messages=[
{"role": "system", "content": f"Summarize {instructions.get(mode, instructions['standard'])}. Be concise."},
{"function": "person", "content material": textual content}])
return r.decisions[0].message.content material
class DataAnalystSkill(Talent):
def _define_metadata(self):
return SkillMetadata(
title="data_analyst",
description="Analyse structured information (JSON or CSV) and extract statistical insights, "
"tendencies, or reply particular questions.",
class=SkillCategory.DATA,
tags=["data", "analysis", "statistics", "csv", "json"],
)
def _define_schema(self):
return {"kind": "object",
"properties": {
"information": {"kind": "string", "description": "Information as JSON array or CSV"},
"query": {"kind": "string", "description": "Analytical query to reply"}},
"required": ["data", "question"]}
def execute(self, information: str, query: str) -> str:
r = consumer.chat.completions.create(
mannequin=MODEL, max_tokens=400,
messages=[
{"role": "user", "content": f"Data:n{data}nnQuestion: {question}"}])
return r.decisions[0].message.content material
class CodeGeneratorSkill(Talent):
def _define_metadata(self):
return SkillMetadata(
title="code_generator",
description="Generate clear, commented Python code for a given process with a quick rationalization.",
class=SkillCategory.GENERATION,
tags=["code", "python", "programming", "script"],
)
def _define_schema(self):
return {"kind": "object",
"properties": {
"process": {"kind": "string"},
"language": {"kind": "string", "default": "python"}},
"required": ["task"]}
def execute(self, process: str, language: str = "python") -> str:
r = consumer.chat.completions.create(
mannequin=MODEL, max_tokens=500,
messages=[
{"role": "system", "content": f"Expert {language} developer. Write clean, commented code with a one-line explanation."},
{"role": "user", "content": task}])
return r.decisions[0].message.content material
