refac
Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com>
This commit is contained in:
co-authored by
Classic298
parent
92a1502126
commit
8be4c5fa6a
@@ -1,5 +1,6 @@
|
||||
import { WEBUI_BASE_URL } from '$lib/constants';
|
||||
import { convertOpenApiToToolPayload } from '$lib/utils';
|
||||
import { normalizeTags } from '$lib/utils/tags';
|
||||
import { getOpenAIModelsDirect } from './openai';
|
||||
|
||||
const TOOL_SERVER_FETCH_TIMEOUT = 10000;
|
||||
@@ -141,8 +142,8 @@ export const getModels = async (
|
||||
}
|
||||
}
|
||||
|
||||
const tags = apiConfig.tags;
|
||||
if (tags) {
|
||||
const tags = normalizeTags(apiConfig.tags);
|
||||
if (tags.length > 0) {
|
||||
for (const model of models) {
|
||||
model.tags = tags;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
import Textarea from './common/Textarea.svelte';
|
||||
import { normalizeTags } from '$lib/utils/tags';
|
||||
|
||||
export let onSubmit: Function = () => {};
|
||||
export let onDelete: Function = () => {};
|
||||
@@ -249,7 +250,7 @@
|
||||
: '';
|
||||
|
||||
enable = connection.config?.enable ?? true;
|
||||
tags = connection.config?.tags ?? [];
|
||||
tags = normalizeTags(connection.config?.tags);
|
||||
prefixId = connection.config?.prefix_id ?? '';
|
||||
passthroughParams = Array.isArray(connection.config?.passthrough_params)
|
||||
? connection.config.passthrough_params.join(', ')
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
export type Tag = { name: string };
|
||||
|
||||
const getTagName = (tag: unknown) => {
|
||||
if (typeof tag === 'string') {
|
||||
return tag;
|
||||
}
|
||||
|
||||
if (typeof tag === 'object' && tag !== null && 'name' in tag) {
|
||||
return (tag as { name?: unknown }).name;
|
||||
}
|
||||
};
|
||||
|
||||
export const normalizeTags = (tags: unknown): Tag[] =>
|
||||
(Array.isArray(tags) ? tags : [])
|
||||
.map(getTagName)
|
||||
.filter((name): name is string => typeof name === 'string' && name.trim() !== '')
|
||||
.map((name) => ({ name: name.trim() }));
|
||||
Reference in New Issue
Block a user