← 返回
未分类

deterministic-calc-skill

Provides secure, sandboxed execution of mathematical expressions and code to deliver exact computation results without model guesswork.
提供安全、沙箱化的数学表达式和代码执行,确保精确计算结果,避免模型猜测。
hardtothinkausername hardtothinkausername 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 352
下载
💾 0
安装
1
版本
#latest

概述

deterministic-calc Skill

核心理念: 大模型擅长预测(猜),但不擅长确定性计算。本 Skill 将确定性计算固化为代码执行,避免模型"猜"结果。


🧠 问题背景

❌ 错误用法:让模型直接计算

用户:123456789 × 987654321 = ?
模型:(开始猜)大概是 121932631...(可能错)

✅ 正确用法:模型生成代码 → 执行 → 返回

用户:123456789 × 987654321 = ?
模型:(生成代码)print(123456789 * 987654321)
执行:121932631112635269
返回:正确答案

📦 安装

npx clawhub install deterministic-calc

🛠️ 可用函数

calculate(expression)

执行数学表达式计算。

参数:

  • expression (string): 数学表达式

返回:

{
  "success": true,
  "expression": "123456789 * 987654321",
  "result": 121932631112635269
}

run_python(code)

执行 Python 代码并返回结果。

参数:

  • code (string): Python 代码

返回:

{
  "success": true,
  "stdout": "121932631112635269\n",
  "stderr": "",
  "exit_code": 0
}

run_shell(command)

执行 Shell 命令并返回结果。

参数:

  • command (string): Shell 命令

返回:

{
  "success": true,
  "stdout": "...",
  "stderr": "",
  "exit_code": 0
}

safe_eval(expression)

安全执行数学表达式(无代码注入风险)。

参数:

  • expression (string): 数学表达式

返回:

{
  "success": true,
  "result": 42
}

📝 使用示例

数学计算

from deterministic_calc import calculate

result = calculate("123456789 * 987654321")
print(result["result"])  # 121932631112635269

复杂计算

from deterministic_calc import run_python

code = """
import math
result = sum(i**2 for i in range(1000))
print(result)
"""
result = run_python(code)
print(result["stdout"])  # 332833500

Shell 命令

from deterministic_calc import run_shell

result = run_shell("ls -la /tmp")
print(result["stdout"])

⚠️ 安全说明

  • calculate()safe_eval() 是沙箱安全的
  • run_python()run_shell() 可执行任意代码,需谨慎使用
  • 生产环境建议只暴露 calculate()safe_eval()

📄 License

MIT

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 10:59 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 41,585
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,884
dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 195 📥 67,668