mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
refac: tool server data handling
This commit is contained in:
parent
c299d3fd54
commit
774c0056bd
1 changed files with 12 additions and 1 deletions
|
|
@ -538,12 +538,23 @@ async def get_tool_server_data(token: str, url: str) -> Dict[str, Any]:
|
||||||
error_body = await response.json()
|
error_body = await response.json()
|
||||||
raise Exception(error_body)
|
raise Exception(error_body)
|
||||||
|
|
||||||
|
text_content = None
|
||||||
|
|
||||||
# Check if URL ends with .yaml or .yml to determine format
|
# Check if URL ends with .yaml or .yml to determine format
|
||||||
if url.lower().endswith((".yaml", ".yml")):
|
if url.lower().endswith((".yaml", ".yml")):
|
||||||
text_content = await response.text()
|
text_content = await response.text()
|
||||||
res = yaml.safe_load(text_content)
|
res = yaml.safe_load(text_content)
|
||||||
else:
|
else:
|
||||||
res = await response.json()
|
text_content = await response.text()
|
||||||
|
|
||||||
|
try:
|
||||||
|
res = json.loads(text_content)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
try:
|
||||||
|
res = yaml.safe_load(text_content)
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
log.exception(f"Could not fetch tool server spec from {url}")
|
log.exception(f"Could not fetch tool server spec from {url}")
|
||||||
if isinstance(err, dict) and "detail" in err:
|
if isinstance(err, dict) and "detail" in err:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue