Merge pull request #12606 from alpha-pet/feat-openapi-yaml-support

Feat: openapi yaml support
This commit is contained in:
Tim Jaeryang Baek
2025-04-09 18:37:09 -07:00
committed by GitHub
4 changed files with 41 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
import { convertOpenApiToToolPayload } from '$lib/utils';
import { getOpenAIModelsDirect } from './openai';
import { parse } from 'yaml';
import { toast } from 'svelte-sonner';
export const getModels = async (
@@ -271,8 +272,15 @@ export const getToolServerData = async (token: string, url: string) => {
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
// Check if URL ends with .yaml or .yml to determine format
if (url.toLowerCase().endsWith('.yaml') || url.toLowerCase().endsWith('.yml')) {
if (!res.ok) throw await res.text();
const text = await res.text();
return parse(text);
} else {
if (!res.ok) throw await res.json();
return res.json();
}
})
.catch((err) => {
console.log(err);