Skip to main content

No project description provided

Project description

软件介绍

依赖环境

python = "^3.10"

软件安装

可以在python虚环境或docker中安装,执行如下命令:

pip install code-exec-hz

默认端口

默认端口是8080,如果需要修改服务端口,请修改文件:site-packages/code_exec/controller/api.py

服务运行

pip安装code-exec-hz后,在当前python环境会增加code-exec命令,直接执行即可启动服务:

code-exec

api调用

按照如下方式,调用接口,可执行code参数中的python代码

curl -XPOST '127.0.0.1:8080/api/exec' \
-H 'Content-Type: application/json' \
-d '{
    "language": "python",
    "inputs":
    {
        "arg1": "参数1"
    },
    "code": "import json\ndata = {\"name\": arg1, \"age\": 18}\njson_str = json.dumps(data, ensure_ascii=False)\nresult = {\"data\": json_str}\n"
}'

response:

{
    "trcid": "oaxdde998771",

    "status": "0",

    "msg": "",

    "result": {}    ## 返回结果,json字符串
}

依赖增加

如果需要增加依赖,比如numpy,直接在安装code-exec的python环境中,安装numpy即可,然后重启服务即可。

pip install numpy
# 结束进程
ps -ef | grep code-exec | grep -v grep | awk '{print $2}' | xargs kill -9
# 启动服务
code-exec

孔明问答集成

配置外部代码执行环境

  1. 调用位置: [孔明问答] -> [控制台] -> [智能体构建] -> 增加[代码执行]节点;
  2. 代码执行节点选择Python语言;
  3. 打开外部环境开关;
  4. 配置外部环境(输入框内填写code-exec服务调用地址),例如: http://127.0.0.1:8080/api/exec ;
  5. 写pyton代码运行智能体。

注意事项

  1. 返回结果参数添加到"data"字段
import json
data = {'name': arg1, 'age': 18}
json_str = json.dumps(data, ensure_ascii=False)
result = {"data": json_str}

在上面代码中,arg1是输入参数,通过上一个节点传入,中间为处理逻辑,最后的result是返回结果,需要遵循json格式,并且将处理好的结果添加到"data"字段中。 因为输出变量是data,这样下一个节点可以获取到data字段中的数据。

  1. 只有在code-exec运行的python环境添加了相应依赖,才能在孔明-代码执行节点引入

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_exec_hz-1.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_exec_hz-1.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file code_exec_hz-1.1.0.tar.gz.

File metadata

  • Download URL: code_exec_hz-1.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.11 Darwin/24.4.0

File hashes

Hashes for code_exec_hz-1.1.0.tar.gz
Algorithm Hash digest
SHA256 143cd6abcbed15c000fb83cd0b1890fde9ec75eb621ecf52f5474c9cb986bff5
MD5 a72031de11c2a8043860b1186400e385
BLAKE2b-256 0f9d21a335e48f170b05142a77af84170ff3111507c064091e03bd86e319aa5c

See more details on using hashes here.

File details

Details for the file code_exec_hz-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: code_exec_hz-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.11 Darwin/24.4.0

File hashes

Hashes for code_exec_hz-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a14162bbca7a1a982a1150ec9e0c06d51078535eb7cf14423e8289585f9dab0a
MD5 fec2ac6e74d7ce2cdfe8f3c177a9b07d
BLAKE2b-256 cf28e9da91f3fac8ccc6d9328493714d3a4470aa41f6a8ce817f150cca64a3bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page