[Bug]沙箱化代码执行器无法正常使用
发生了什么
TypeError: Main.python_interpreter() got an unexpected keyword argument 'code'
如何复现?
6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
docker compose 部署astrbot,docker_compose.yaml中添加volumes:
- /var/run/docker.sock:/var/run/docker.sock, docker compose up -d,部署napcat和napcat cli,napcat start qq登录,配置ws,修改astrbot配置
AstrBot 版本与部署方式
v3.4.28 Docker
操作系统
Linux
额外信息
报错信息
[01:55:05| WARNING] [llm_request.py:120]: Traceback (most recent call last):
File "/AstrBot/astrbot/core/pipeline/stage.py", line 45, in _call_handler
ready_to_call = handler(event, **params)
TypeError: Main.python_interpreter() got an unexpected keyword argument 'code'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/AstrBot/astrbot/core/pipeline/process_stage/method/llm_request.py", line 113, in process
async for resp in wrapper:
File "/AstrBot/astrbot/core/pipeline/stage.py", line 48, in _call_handler
ready_to_call = handler(event, ctx.plugin_manager.context, **params)
TypeError: Main.python_interpreter() got an unexpected keyword argument 'code'
完整配置
[01:55:02| INFO] [event_bus.py:21]: [aiocqhttp] /kyan1823: /执行代码 返还1-1000的随机数
[01:55:04| INFO] [llm_request.py:109]: 调用工具函数:python_interpreter,参数:{'code': 'import random\nrandom_number = random.randint(1, 1000)\nrandom_number'}
[01:55:05| WARNING] [llm_request.py:120]: Traceback (most recent call last):
File "/AstrBot/astrbot/core/pipeline/stage.py", line 45, in _call_handler
ready_to_call = handler(event, **params)
TypeError: Main.python_interpreter() got an unexpected keyword argument 'code'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/AstrBot/astrbot/core/pipeline/process_stage/method/llm_request.py", line 113, in process
async for resp in wrapper:
File "/AstrBot/astrbot/core/pipeline/stage.py", line 48, in _call_handler
ready_to_call = handler(event, ctx.plugin_manager.context, **params)
TypeError: Main.python_interpreter() got an unexpected keyword argument 'code'
[01:55:10| INFO] [stage.py:87]: AstrBot -> /kyan1823: 抱歉,执行代码时出现了错误。我可以为你提供一个在本地生成随机数的Python代码示例:
import random
random_number = random.randint(1, 1000)
print(random_number)
你可以在你的Python环境中运行此代码。
docker 配置
root@iZm5e2j6ubsfdwsi3d7bovZ:~/AstrBot# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89d14f7e2977 soulter/astrbot:latest "python main.py" 16 hours ago Up 16 hours 0.0.0.0:6180-6200->6180-6200/tcp, :::6180-6200->6180-6200/tcp, 0.0.0.0:11451->11451/tcp, :::11451->11451/tcp astrbot
root@iZm5e2j6ubsfdwsi3d7bovZ:~/AstrBot# docker inspect 89d14f7e2977
[
{
"Id": "89d14f7e297754ad1e5f2043b9531d243c6cc91de376d8248a1e90017efdaae5",
"Created": "2025-02-16T13:36:46.304551331Z",
"Path": "python",
"Args": [
"main.py"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 1886415,
"ExitCode": 0,
"Error": "",
"StartedAt": "2025-02-16T13:36:47.365836355Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:0d049679cfb433da6ce7cf68b796e6d804016cb834c637ac8668f23d5430c4dc",
"ResolvConfPath": "/var/lib/docker/containers/89d14f7e297754ad1e5f2043b9531d243c6cc91de376d8248a1e90017efdaae5/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/89d14f7e297754ad1e5f2043b9531d243c6cc91de376d8248a1e90017efdaae5/hostname",
"HostsPath": "/var/lib/docker/containers/89d14f7e297754ad1e5f2043b9531d243c6cc91de376d8248a1e90017efdaae5/hosts",
"LogPath": "/var/lib/docker/containers/89d14f7e297754ad1e5f2043b9531d243c6cc91de376d8248a1e90017efdaae5/89d14f7e297754ad1e5f2043b9531d243c6cc91de376d8248a1e90017efdaae5-json.log",
"Name": "/astrbot",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/var/run/docker.sock:/var/run/docker.sock:rw",
"/root/AstrBot/data:/AstrBot/data:rw"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "astrbot_default",
"PortBindings": {
"11451/tcp": [
{
"HostIp": "",
"HostPort": "11451"
}
],
"6180/tcp": [
{
"HostIp": "",
"HostPort": "6180"
}
],
"6181/tcp": [
{
"HostIp": "",
"HostPort": "6181"
}
],
"6182/tcp": [
{
"HostIp": "",
"HostPort": "6182"
}
],
"6183/tcp": [
{
"HostIp": "",
"HostPort": "6183"
}
],
"6184/tcp": [
{
"HostIp": "",
"HostPort": "6184"
}
],
"6185/tcp": [
{
"HostIp": "",
"HostPort": "6185"
}
],
"6186/tcp": [
{
"HostIp": "",
"HostPort": "6186"
}
],
"6187/tcp": [
{
"HostIp": "",
"HostPort": "6187"
}
],
"6188/tcp": [
{
"HostIp": "",
"HostPort": "6188"
}
],
"6189/tcp": [
{
"HostIp": "",
"HostPort": "6189"
}
],
"6190/tcp": [
{
"HostIp": "",
"HostPort": "6190"
}
],
"6191/tcp": [
{
"HostIp": "",
"HostPort": "6191"
}
],
"6192/tcp": [
{
"HostIp": "",
"HostPort": "6192"
}
],
"6193/tcp": [
{
"HostIp": "",
"HostPort": "6193"
}
],
"6194/tcp": [
{
"HostIp": "",
"HostPort": "6194"
}
],
"6195/tcp": [
{
"HostIp": "",
"HostPort": "6195"
}
],
"6196/tcp": [
{
"HostIp": "",
"HostPort": "6196"
}
],
"6197/tcp": [
{
"HostIp": "",
"HostPort": "6197"
}
],
"6198/tcp": [
{
"HostIp": "",
"HostPort": "6198"
}
],
"6199/tcp": [
{
"HostIp": "",
"HostPort": "6199"
}
],
"6200/tcp": [
{
"HostIp": "",
"HostPort": "6200"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"ConsoleSize": [
0,
0
],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "private",
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": [],
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": null,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware",
"/sys/devices/virtual/powercap"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/4043680d9e7a6e4c2bd30b2adbbf8a72dae06255e9947c18448e167f11fc4b94-init/diff:/var/lib/docker/overlay2/4502ec616dc387a789d4aa2d9b81c0265d4b820b9d98ee5a3f0198df17e4469e/diff:/var/lib/docker/overlay2/bbb13ce7705080c569b40d30eb9dce16db52e3d36e0783a363866da10718b794/diff:/var/lib/docker/overlay2/3056dbc18fb0c9313d072c275ec46e0c82a2fa4ccf4a91c36dc5c9812fa892c5/diff:/var/lib/docker/overlay2/5f0f2fd0730c988982bd4c9fc3559f28ec81c623c98693e929ae6719a34080a0/diff:/var/lib/docker/overlay2/b3365f1bece674cb9b689c6963c8aa82df8b93e981685b36d5028a3db1b9aab0/diff:/var/lib/docker/overlay2/5c2138b2301f7d9fce8986da6f3871681f0c1426976adecac0a541261db55728/diff:/var/lib/docker/overlay2/f3fb710cfaff8adeb6c766806b878d8cfb60b6c899789791dad34686196a1dab/diff:/var/lib/docker/overlay2/50d2e79171112b58b97c7c3d18ebd26d357f5e9e57553865ae1924c4bbf2e3c8/diff:/var/lib/docker/overlay2/b57a6adca0e9f95b92b768174f6b9c8dd2759e2c13730c31b3d534d3bed66863/diff",
"MergedDir": "/var/lib/docker/overlay2/4043680d9e7a6e4c2bd30b2adbbf8a72dae06255e9947c18448e167f11fc4b94/merged",
"UpperDir": "/var/lib/docker/overlay2/4043680d9e7a6e4c2bd30b2adbbf8a72dae06255e9947c18448e167f11fc4b94/diff",
"WorkDir": "/var/lib/docker/overlay2/4043680d9e7a6e4c2bd30b2adbbf8a72dae06255e9947c18448e167f11fc4b94/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Destination": "/var/run/docker.sock",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/root/AstrBot/data",
"Destination": "/AstrBot/data",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "89d14f7e2977",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"11451/tcp": {},
"6180/tcp": {},
"6181/tcp": {},
"6182/tcp": {},
"6183/tcp": {},
"6184/tcp": {},
"6185/tcp": {},
"6186/tcp": {},
"6187/tcp": {},
"6188/tcp": {},
"6189/tcp": {},
"6190/tcp": {},
"6191/tcp": {},
"6192/tcp": {},
"6193/tcp": {},
"6194/tcp": {},
"6195/tcp": {},
"6196/tcp": {},
"6197/tcp": {},
"6198/tcp": {},
"6199/tcp": {},
"6200/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"GPG_KEY=A035C8C19219BA821ECEA86B64E628F8D684696D",
"PYTHON_VERSION=3.10.16",
"PYTHON_SHA256=bfb249609990220491a1b92850a07135ed0831e41738cf681d63cf01b2a8fbd1"
],
"Cmd": [
"python",
"main.py"
],
"Image": "soulter/astrbot:latest",
"Volumes": null,
"WorkingDir": "/AstrBot",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "4d98e5ba7a6b83bf52e588416976f8e2935a50994d8d345503ced040770a76b0",
"com.docker.compose.container-number": "1",
"com.docker.compose.depends_on": "",
"com.docker.compose.image": "sha256:0d049679cfb433da6ce7cf68b796e6d804016cb834c637ac8668f23d5430c4dc",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "astrbot",
"com.docker.compose.project.config_files": "/root/AstrBot/compose.yml",
"com.docker.compose.project.working_dir": "/root/AstrBot",
"com.docker.compose.service": "astrbot",
"com.docker.compose.version": "2.29.7"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "50ced9786f04864828edf3998c98005f1ebeaa9b31556f6c2692b0aa47e8f4fc",
"SandboxKey": "/var/run/docker/netns/50ced9786f04",
"Ports": {
"11451/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "11451"
},
{
"HostIp": "::",
"HostPort": "11451"
}
],
"6180/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6180"
},
{
"HostIp": "::",
"HostPort": "6180"
}
],
"6181/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6181"
},
{
"HostIp": "::",
"HostPort": "6181"
}
],
"6182/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6182"
},
{
"HostIp": "::",
"HostPort": "6182"
}
],
"6183/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6183"
},
{
"HostIp": "::",
"HostPort": "6183"
}
],
"6184/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6184"
},
{
"HostIp": "::",
"HostPort": "6184"
}
],
"6185/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6185"
},
{
"HostIp": "::",
"HostPort": "6185"
}
],
"6186/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6186"
},
{
"HostIp": "::",
"HostPort": "6186"
}
],
"6187/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6187"
},
{
"HostIp": "::",
"HostPort": "6187"
}
],
"6188/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6188"
},
{
"HostIp": "::",
"HostPort": "6188"
}
],
"6189/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6189"
},
{
"HostIp": "::",
"HostPort": "6189"
}
],
"6190/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6190"
},
{
"HostIp": "::",
"HostPort": "6190"
}
],
"6191/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6191"
},
{
"HostIp": "::",
"HostPort": "6191"
}
],
"6192/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6192"
},
{
"HostIp": "::",
"HostPort": "6192"
}
],
"6193/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6193"
},
{
"HostIp": "::",
"HostPort": "6193"
}
],
"6194/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6194"
},
{
"HostIp": "::",
"HostPort": "6194"
}
],
"6195/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6195"
},
{
"HostIp": "::",
"HostPort": "6195"
}
],
"6196/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6196"
},
{
"HostIp": "::",
"HostPort": "6196"
}
],
"6197/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6197"
},
{
"HostIp": "::",
"HostPort": "6197"
}
],
"6198/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6198"
},
{
"HostIp": "::",
"HostPort": "6198"
}
],
"6199/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6199"
},
{
"HostIp": "::",
"HostPort": "6199"
}
],
"6200/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "6200"
},
{
"HostIp": "::",
"HostPort": "6200"
}
]
},
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"astrbot_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"astrbot",
"astrbot"
],
"MacAddress": "02:42:ac:13:00:02",
"DriverOpts": null,
"NetworkID": "78f43e5ed936a3b68e2a265a5b508af1f102723a44bb598b8bc703622b7cb8b7",
"EndpointID": "79f3963ce453f97967b7d34e5aac39fd434b8d04579c9f6e73526025d6c24263",
"Gateway": "172.19.0.1",
"IPAddress": "172.19.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DNSNames": [
"astrbot",
"89d14f7e2977"
]
}
}
}
}
]
cmd_config.json
{
"config_version": 2,
"platform_settings": {
"unique_session": false,
"rate_limit": {
"time": 60,
"count": 30,
"strategy": "stall"
},
"reply_prefix": "",
"forward_threshold": 100000,
"enable_id_white_list": false,
"id_whitelist": [],
"id_whitelist_log": true,
"wl_ignore_admin_on_group": true,
"wl_ignore_admin_on_friend": true,
"reply_with_mention": false,
"reply_with_quote": true,
"path_mapping": [],
"segmented_reply": {
"enable": true,
"only_llm_result": true,
"interval_method": "random",
"interval": "1.5,3.5",
"log_base": 2.6,
"words_count_threshold": 150,
"regex": ".*?[。?!~…]+|.+$",
"content_cleanup_rule": ""
},
"no_permission_reply": true
},
"provider": [
{
"id": "qhaigc",
"type": "openai_chat_completion",
"enable": true,
"key": [
"sk-CC6zFfnfooZQmGoN7fA42192B8294984B7EeDeB88eC3De4c"
],
"api_base": "https://api.qhaigc.net/v1",
"timeout": 120,
"model_config": {
"model": "chatgpt-4o-latest"
}
}
],
"provider_settings": {
"enable": true,
"wake_prefix": "",
"web_search": true,
"web_search_link": true,
"identifier": true,
"datetime_system_prompt": true,
"default_personality": "default",
"prompt_prefix": ""
},
"provider_stt_settings": {
"enable": false,
"provider_id": ""
},
"provider_tts_settings": {
"enable": false,
"provider_id": ""
},
"provider_ltm_settings": {
"group_icl_enable": true,
"group_message_max_cnt": 300,
"image_caption": false,
"image_caption_provider_id": "",
"image_caption_prompt": "Please describe the image using Chinese.",
"active_reply": {
"enable": true,
"method": "possibility_reply",
"possibility_reply": 0.1,
"prompt": "",
"whitelist": []
}
},
"content_safety": {
"also_use_in_response": false,
"internal_keywords": {
"enable": true,
"extra_keywords": []
},
"baidu_aip": {
"enable": false,
"app_id": "",
"api_key": "",
"secret_key": ""
}
},
"admins_id": [
"astrbot"
],
"t2i": false,
"t2i_word_threshold": 150,
"http_proxy": "",
"dashboard": {
"enable": true,
"username": "kyan",
"password": "d637ca24f952a144a118f41887900c77",
"port": 6185
},
"platform": [
{
"id": "default",
"type": "aiocqhttp",
"enable": true,
"ws_reverse_host": "0.0.0.0",
"ws_reverse_port": 6199
}
],
"wake_prefix": [
"/"
],
"log_level": "INFO",
"t2i_endpoint": "",
"pip_install_arg": "",
"plugin_repo_mirror": "",
"knowledge_db": {},
"persona": []
}
你愿意提交 PR 吗?
- [ ] 是的,我愿意提交 PR!
Code of Conduct
- [x] 我已阅读并同意遵守该项目的 行为准则。
部署没有问题,这个应该是模型性能原因返回了非预期的参数导致没有正常调用代码执行器。可以重复请求试试。这是一个概率性问题。具体来说,这个函数工具对应的函数不接受任何参数,而llm返回的函数参数中带了一个 code 参数导致了调用错误。
请问官方文档里的demo用的是哪个平台哪个模型的api呢 我想试试一样的,我用的这个一次也没有成功过
以及 把函数不接受任何参数告诉llm后出现了新的错误
[14:26:42| INFO] [event_bus.py:21]: [aiocqhttp] /kyan1823: /执行代码 生成一个1-100的随机数
[14:26:51| INFO] [stage.py:87]: AstrBot -> /kyan1823: 你好!请问有什么我可以帮助你的吗?😊
[14:26:53| INFO] [llm_request.py:109]: 调用工具函数:python_interpreter,参数:{'code': 'import random\n\n# 生成一个1到100的随机数\nrandom_number = random.randint(1, 100)\nrandom_number'}
[14:26:53| WARNING] [llm_request.py:120]: Traceback (most recent call last):
File "/AstrBot/astrbot/core/pipeline/stage.py", line 45, in _call_handler
ready_to_call = handler(event, **params)
TypeError: Main.python_interpreter() got an unexpected keyword argument 'code'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/AstrBot/astrbot/core/pipeline/process_stage/method/llm_request.py", line 113, in process
async for resp in wrapper:
File "/AstrBot/astrbot/core/pipeline/stage.py", line 48, in _call_handler
ready_to_call = handler(event, ctx.plugin_manager.context, **params)
TypeError: Main.python_interpreter() got an unexpected keyword argument 'code'
[14:27:12| INFO] [stage.py:87]: AstrBot -> /kyan1823: 这个错误显示 python_interpreter() 函数不接受 code 参数,这说明工具的调用中参数名使用错误或者实际调用方式存在问题。以下是进一步排查和解决问题的步骤:
解决方法
检查 python_interpreter() 的正确参数
-
确认支持的参数名:
- 错误信息表明
python_interpreter()没有名为code的参数,因此需要检查函数的正确参数名。 - 常见的参数名可能是
script、payload或直接未命名的入参。
- 错误信息表明
-
修改代码,直接传递 Python 脚本字符串: 如果
python_interpreter可直接接收代码字符串作为第一个入参,尝试以下方式:python_interpreter("""
import random random_number = random.randint(1, 100) print(random_number) """)
#### **如果需要命名参数**
无明确文档的情况下,通用的参数名需要逐个尝试:
- 尝试使用 `'script'` 代替 `'code'`
- 或者直接将代码作为参数:
```python
response = python_interpreter({
'script': """
import random
rand = random.randint(1, 100)
print(rand)
"""
})
本地调试代码
如果 python_interpreter 工具无法正确运行,您可以尝试直接在本地 Python 环境中运行代码:
- 打开 Python 环境 (
python). - 输入以下内容运行随机数生成:
import random print(random.randint(1, 100))
如果问题仍然未解决
根据现有的错误信息,如果错误重复出现:
- 请提供
python_interpreter()方法定义,以便进一步分析如何调用函数。 - 您可以提供工具接口文档或更多上下文信息,我会进一步为您排查问题。
希望这会有所帮助!如果仍有疑问,欢迎随时告诉我。😊
[14:27:50| INFO] [event_bus.py:21]: [aiocqhttp] /kyan1823: python_intetperter 不接受任何参数,再试试
[14:28:02| INFO] [llm_request.py:109]: 调用工具函数:python_interpreter,参数:{}
Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x76b92565e620>, 9070677.502500547)])']
connector: <aiohttp.connector.UnixConnector object at 0x76b92569aaa0>
[14:28:09| INFO] [stage.py:87]: AstrBot -> /kyan1823: [Reply]使用沙箱执行代码中,请稍等...(尝试次数: 1/5)
[14:28:11| WARNING] [main.py:363]: 未从沙箱输出中捕获到合法的输出。沙箱输出日志: ["python: can't open file '/astrbot_sandbox/exec.py': [Errno 2] No such file or directory\n"]
[14:28:13| INFO] [stage.py:87]: AstrBot -> /kyan1823: [Reply]经过多次尝试后,未从沙箱输出中捕获到合法的输出,请更换问法或者查看日志。
目前发现了一个逻辑性问题导致可能docker部署的astrbot无法使用代码执行器,正在研究解决办法...
目前找到了一种docker下可以顺利执行astrbot的代码执行器的方法,就是有点麻烦
目前发现了一个逻辑性问题导致可能docker部署的astrbot无法使用代码执行器,正在研究解决办法...
https://github.com/Soulter/AstrBot-docs/pull/5/commits/42f2dd4383b4d05069b3de4031ebb632dcb73895 我提了一个pr
新版本提供了相关支持:https://astrbot.app/use/code-interpreter.html#linux-docker-%E5%90%AF%E5%8A%A8-astrbot