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.2.tar.gz (8.3 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.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: code_exec_hz-1.1.2.tar.gz
  • Upload date:
  • Size: 8.3 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.2.tar.gz
Algorithm Hash digest
SHA256 8617f9c69ae3a8f102492e209bb40db44454b2b787f5218d31e07103bf3d571f
MD5 9be95fcbff93246ac9484eab966530ac
BLAKE2b-256 f36f58aee5d90148b6248b763a2b0cf97ffeb1d839b69fc76b7a107b30d091b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: code_exec_hz-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9717641c48f2f12d4b5a9b1aba2d7b62cffdab6ec03f608e85c232e9ed2110b2
MD5 5763b5a544d28aa9a4e8938a3e631b29
BLAKE2b-256 59bd530af809589638b7a563e63d7a37dc47a977bcca29fca0cabd46595189d9

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