api tool support multiple env url (#12249)

Co-authored-by: mabo <mabo@aeyes.ai>
This commit is contained in:
mbo 2025-01-13 17:49:30 +08:00 committed by GitHub
parent 69d58fbb50
commit 1859d57784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ from json import loads as json_loads
from json.decoder import JSONDecodeError from json.decoder import JSONDecodeError
from typing import Optional from typing import Optional
from flask import request
from requests import get from requests import get
from yaml import YAMLError, safe_load # type: ignore from yaml import YAMLError, safe_load # type: ignore
@ -29,6 +30,10 @@ class ApiBasedToolSchemaParser:
raise ToolProviderNotFoundError("No server found in the openapi yaml.") raise ToolProviderNotFoundError("No server found in the openapi yaml.")
server_url = openapi["servers"][0]["url"] server_url = openapi["servers"][0]["url"]
request_env = request.headers.get("X-Request-Env")
if request_env:
matched_servers = [server["url"] for server in openapi["servers"] if server["env"] == request_env]
server_url = matched_servers[0] if matched_servers else server_url
# list all interfaces # list all interfaces
interfaces = [] interfaces = []