← 返回聊天
新建
删除
Models
gpt5.php
gpt5_file.php
gpt5_mini_file.php
openai_chat.php
Tools
get_time.php
get_weather.php
global_search_messages.php
math.php
memo.php
news.php
search_arxiv.php
search_crossref.php
search_github_code.php
search_pubmed.php
search_semantic_scholar.php
stock_market.php
url.php
<?php declare(strict_types=1); return [ 'name' => 'math', 'description' => '做简单四则运算。支持加(add)、减(sub)、乘(mul)、除(div)。', 'parameters' => [ 'type' => 'object', 'properties' => [ 'a' => ['type' => 'number', 'description' => '第一个数'], 'b' => ['type' => 'number', 'description' => '第二个数'], 'op' => ['type' => 'string', 'description' => '运算符: add/sub/mul/div'], ], 'required' => ['a', 'b', 'op'], ], 'run' => function(array $args, array $context) { $a = (float)$args['a']; $b = (float)$args['b']; $op = strtolower(trim((string)$args['op'])); switch ($op) { case 'add': $v = $a + $b; break; case 'sub': $v = $a - $b; break; case 'mul': $v = $a * $b; break; case 'div': if ($b == 0.0) throw new RuntimeException('除数不能为 0'); $v = $a / $b; break; default: throw new RuntimeException('不支持的 op: ' . $op . '(请用 add/sub/mul/div)'); } return [ 'a' => $a, 'b' => $b, 'op' => $op, 'result' => $v, ]; }, ];
保存