mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
Merge pull request #16096 from gkkachi/dev
fix: properly handle full URLs in form_data.path
This commit is contained in:
commit
1f22e1d84c
2 changed files with 20 additions and 11 deletions
|
|
@ -7,7 +7,11 @@ from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||||
from open_webui.config import get_config, save_config
|
from open_webui.config import get_config, save_config
|
||||||
from open_webui.config import BannerModel
|
from open_webui.config import BannerModel
|
||||||
|
|
||||||
from open_webui.utils.tools import get_tool_server_data, get_tool_servers_data
|
from open_webui.utils.tools import (
|
||||||
|
get_tool_server_data,
|
||||||
|
get_tool_servers_data,
|
||||||
|
build_tool_server_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
@ -135,7 +139,7 @@ async def verify_tool_servers_config(
|
||||||
elif form_data.auth_type == "session":
|
elif form_data.auth_type == "session":
|
||||||
token = request.state.token.credentials
|
token = request.state.token.credentials
|
||||||
|
|
||||||
url = f"{form_data.url}/{form_data.path}"
|
url = build_tool_server_url(form_data.url, form_data.path)
|
||||||
return await get_tool_server_data(token, url)
|
return await get_tool_server_data(token, url)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|
|
||||||
|
|
@ -489,15 +489,7 @@ async def get_tool_servers_data(
|
||||||
if server.get("config", {}).get("enable"):
|
if server.get("config", {}).get("enable"):
|
||||||
# Path (to OpenAPI spec URL) can be either a full URL or a path to append to the base URL
|
# Path (to OpenAPI spec URL) can be either a full URL or a path to append to the base URL
|
||||||
openapi_path = server.get("path", "openapi.json")
|
openapi_path = server.get("path", "openapi.json")
|
||||||
if "://" in openapi_path:
|
full_url = build_tool_server_url(server.get("url"), openapi_path)
|
||||||
# If it contains "://", it's a full URL
|
|
||||||
full_url = openapi_path
|
|
||||||
else:
|
|
||||||
if not openapi_path.startswith("/"):
|
|
||||||
# Ensure the path starts with a slash
|
|
||||||
openapi_path = f"/{openapi_path}"
|
|
||||||
|
|
||||||
full_url = f"{server.get('url')}{openapi_path}"
|
|
||||||
|
|
||||||
info = server.get("info", {})
|
info = server.get("info", {})
|
||||||
|
|
||||||
|
|
@ -643,3 +635,16 @@ async def execute_tool_server(
|
||||||
error = str(err)
|
error = str(err)
|
||||||
log.exception(f"API Request Error: {error}")
|
log.exception(f"API Request Error: {error}")
|
||||||
return {"error": error}
|
return {"error": error}
|
||||||
|
|
||||||
|
|
||||||
|
def build_tool_server_url(url: Optional[str], path: str) -> str:
|
||||||
|
"""
|
||||||
|
Build the full URL for a tool server, given a base url and a path.
|
||||||
|
"""
|
||||||
|
if "://" in path:
|
||||||
|
# If it contains "://", it's a full URL
|
||||||
|
return path
|
||||||
|
if not path.startswith("/"):
|
||||||
|
# Ensure the path starts with a slash
|
||||||
|
path = f"/{path}"
|
||||||
|
return f"{url}{path}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue