mirror of
https://github.com/open-webui/computer.git
synced 2026-11-23 22:11:29 -05:00
refac
This commit is contained in:
1 parent
f9d1d8cdaf
commit
b6c46ab00a
5 files changed
+245
-34
No files matched your search
+17
-5
@@ -9,7 +9,6 @@ from __future__ import annotations
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -66,9 +65,7 @@ async def fetch_openapi_spec(
|
||||
# ── Schema conversion ──────────────────────────────────────
|
||||
|
||||
|
||||
def _resolve_schema(
|
||||
schema: dict, components: dict, resolved: set | None = None
|
||||
) -> dict:
|
||||
def _resolve_schema(schema: dict, components: dict, resolved: set | None = None) -> dict:
|
||||
"""Recursively resolve $ref references in a JSON schema."""
|
||||
if not schema:
|
||||
return {}
|
||||
@@ -168,7 +165,7 @@ def convert_openapi_to_tool_specs(openapi_spec: dict) -> list[dict]:
|
||||
pschema = param.get("schema", {})
|
||||
desc = pschema.get("description", "") or param.get("description", "")
|
||||
if pschema.get("enum") and isinstance(pschema["enum"], list):
|
||||
desc += f'. Possible values: {", ".join(str(v) for v in pschema["enum"])}'
|
||||
desc += f". Possible values: {', '.join(str(v) for v in pschema['enum'])}"
|
||||
|
||||
prop = {
|
||||
"type": pschema.get("type") or "string",
|
||||
@@ -298,6 +295,21 @@ async def execute_openapi_tool(
|
||||
json=body_params if body_params else None,
|
||||
)
|
||||
|
||||
if resp.status_code >= 400:
|
||||
body = resp.text.strip()
|
||||
try:
|
||||
body = json.dumps(resp.json(), indent=2, ensure_ascii=False)
|
||||
except Exception:
|
||||
pass
|
||||
return json.dumps(
|
||||
{
|
||||
"error": f"HTTP {resp.status_code} from tool server",
|
||||
"status_code": resp.status_code,
|
||||
"body": body[:4000],
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
|
||||
# Try to parse as JSON
|
||||
try:
|
||||
data = resp.json()
|
||||
|
||||
Reference in new issue
Block a user