diff --git a/docs/docs/tools/builtin.md b/docs/docs/tools/builtin.md index b262e875..5d232513 100644 --- a/docs/docs/tools/builtin.md +++ b/docs/docs/tools/builtin.md @@ -146,6 +146,7 @@ veADK 集成了以下火山引擎工具: - `AGENTKIT_TOOL_ID`:用于调用火山引擎AgentKit Tools的沙箱环境Id - `AGENTKIT_TOOL_HOST`:用于调用火山引擎AgentKit Tools的EndPoint - `AGENTKIT_TOOL_SERVICE_CODE`:用于调用AgentKit Tools的ServiceCode + - `AGENTKIT_TOOL_SCHEME`:用于切换调用 AgentKit Tools 的协议,允许 `http`/`https`,默认 `https` 环境变量列表: diff --git a/veadk/tools/builtin_tools/run_code.py b/veadk/tools/builtin_tools/run_code.py index 4e05fe2d..8a1c0fe5 100644 --- a/veadk/tools/builtin_tools/run_code.py +++ b/veadk/tools/builtin_tools/run_code.py @@ -49,6 +49,9 @@ def run_code( host = getenv( "AGENTKIT_TOOL_HOST", service + "." + region + ".volces.com" ) # temporary host for code run tool + scheme = getenv("AGENTKIT_TOOL_SCHEME", "https", allow_false_values=True).lower() + if scheme not in {"http", "https"}: + scheme = "https" logger.debug(f"tools endpoint: {host}") session_id = tool_context._invocation_context.session.id @@ -103,6 +106,7 @@ def run_code( region=region, host=host, header=header, + scheme=scheme, ) logger.debug(f"Invoke run code response: {res}") diff --git a/veadk/utils/volcengine_sign.py b/veadk/utils/volcengine_sign.py index b47b6571..db8f5c68 100644 --- a/veadk/utils/volcengine_sign.py +++ b/veadk/utils/volcengine_sign.py @@ -25,6 +25,7 @@ Region = "" Host = "" ContentType = "" +Scheme = "https" def norm_query(params): @@ -59,7 +60,17 @@ def hash_sha256(content: str): # 第二步:签名请求函数 -def request(method, date, query, header, ak, sk, action, body): +def request( + method, + date, + query, + header, + ak, + sk, + action, + body, + scheme: Literal["http", "https"] = "https", +): # 第三步:创建身份证明。其中的 Service 和 Region 字段是固定的。ak 和 sk 分别代表 # AccessKeyID 和 SecretAccessKey。同时需要初始化签名结构体。一些签名计算时需要的属性也在这里处理。 # 初始化身份证明结构体 @@ -151,7 +162,7 @@ def request(method, date, query, header, ak, sk, action, body): # 第六步:将 Signature 签名写入 HTTP Header 中,并发送 HTTP 请求。 r = requests.request( method=method, - url="https://{}{}".format(request_param["host"], request_param["path"]), + url=f"{scheme}://{request_param['host']}{request_param['path']}", headers=header, params=request_param["query"], data=request_param["body"], @@ -175,6 +186,7 @@ def ve_request( header: dict = {}, query: dict = {}, method: Literal["GET", "POST", "PUT", "DELETE"] = "POST", + scheme: Literal["http", "https"] = "https", ): global Service Service = service @@ -186,6 +198,8 @@ def ve_request( Host = host global ContentType ContentType = content_type + global Scheme + Scheme = scheme AK = ak SK = sk now = datetime.datetime.utcnow() @@ -195,7 +209,15 @@ def ve_request( try: response_body = request( - method, now, query, header, AK, SK, action, json.dumps(request_body) + method, + now, + query, + header, + AK, + SK, + action, + json.dumps(request_body), + Scheme, ) return response_body except Exception as e: