2024-05-26 16:23:24 +00:00
|
|
|
|
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
2025-03-27 09:27:56 +00:00
|
|
|
|
import { convertOpenApiToToolPayload } from '$lib/utils';
|
2025-02-12 09:17:30 +00:00
|
|
|
|
import { getOpenAIModelsDirect } from './openai';
|
2023-12-26 19:32:22 +00:00
|
|
|
|
|
2025-02-12 09:17:30 +00:00
|
|
|
|
export const getModels = async (
|
|
|
|
|
|
token: string = '',
|
|
|
|
|
|
connections: object | null = null,
|
|
|
|
|
|
base: boolean = false
|
|
|
|
|
|
) => {
|
2024-05-24 08:40:48 +00:00
|
|
|
|
let error = null;
|
2024-11-17 07:46:12 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/models${base ? '/base' : ''}`, {
|
2024-05-24 08:40:48 +00:00
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
error = err;
|
2024-11-16 03:14:24 +00:00
|
|
|
|
console.log(err);
|
2024-05-24 08:40:48 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-24 09:17:48 +00:00
|
|
|
|
let models = res?.data ?? [];
|
2025-02-12 09:17:30 +00:00
|
|
|
|
|
|
|
|
|
|
if (connections && !base) {
|
|
|
|
|
|
let localModels = [];
|
|
|
|
|
|
|
|
|
|
|
|
if (connections) {
|
|
|
|
|
|
const OPENAI_API_BASE_URLS = connections.OPENAI_API_BASE_URLS;
|
|
|
|
|
|
const OPENAI_API_KEYS = connections.OPENAI_API_KEYS;
|
|
|
|
|
|
const OPENAI_API_CONFIGS = connections.OPENAI_API_CONFIGS;
|
|
|
|
|
|
|
|
|
|
|
|
const requests = [];
|
|
|
|
|
|
for (const idx in OPENAI_API_BASE_URLS) {
|
|
|
|
|
|
const url = OPENAI_API_BASE_URLS[idx];
|
|
|
|
|
|
|
|
|
|
|
|
if (idx.toString() in OPENAI_API_CONFIGS) {
|
|
|
|
|
|
const apiConfig = OPENAI_API_CONFIGS[idx.toString()] ?? {};
|
|
|
|
|
|
|
|
|
|
|
|
const enable = apiConfig?.enable ?? true;
|
|
|
|
|
|
const modelIds = apiConfig?.model_ids ?? [];
|
|
|
|
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
|
|
if (modelIds.length > 0) {
|
|
|
|
|
|
const modelList = {
|
|
|
|
|
|
object: 'list',
|
|
|
|
|
|
data: modelIds.map((modelId) => ({
|
|
|
|
|
|
id: modelId,
|
|
|
|
|
|
name: modelId,
|
|
|
|
|
|
owned_by: 'openai',
|
|
|
|
|
|
openai: { id: modelId },
|
|
|
|
|
|
urlIdx: idx
|
|
|
|
|
|
}))
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-02-12 09:32:49 +00:00
|
|
|
|
requests.push(
|
|
|
|
|
|
(async () => {
|
|
|
|
|
|
return modelList;
|
|
|
|
|
|
})()
|
|
|
|
|
|
);
|
2025-02-12 09:17:30 +00:00
|
|
|
|
} else {
|
2025-02-13 07:33:53 +00:00
|
|
|
|
requests.push(
|
|
|
|
|
|
(async () => {
|
|
|
|
|
|
return await getOpenAIModelsDirect(url, OPENAI_API_KEYS[idx])
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
return res;
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
return {
|
|
|
|
|
|
object: 'list',
|
|
|
|
|
|
data: [],
|
|
|
|
|
|
urlIdx: idx
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
})()
|
|
|
|
|
|
);
|
2025-02-12 09:17:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-02-12 09:32:49 +00:00
|
|
|
|
requests.push(
|
|
|
|
|
|
(async () => {
|
|
|
|
|
|
return {
|
|
|
|
|
|
object: 'list',
|
|
|
|
|
|
data: [],
|
|
|
|
|
|
urlIdx: idx
|
|
|
|
|
|
};
|
|
|
|
|
|
})()
|
|
|
|
|
|
);
|
2025-02-12 09:17:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-12 09:32:49 +00:00
|
|
|
|
|
2025-02-12 09:17:30 +00:00
|
|
|
|
const responses = await Promise.all(requests);
|
|
|
|
|
|
|
|
|
|
|
|
for (const idx in responses) {
|
|
|
|
|
|
const response = responses[idx];
|
|
|
|
|
|
const apiConfig = OPENAI_API_CONFIGS[idx.toString()] ?? {};
|
|
|
|
|
|
|
|
|
|
|
|
let models = Array.isArray(response) ? response : (response?.data ?? []);
|
|
|
|
|
|
models = models.map((model) => ({ ...model, openai: { id: model.id }, urlIdx: idx }));
|
|
|
|
|
|
|
|
|
|
|
|
const prefixId = apiConfig.prefix_id;
|
|
|
|
|
|
if (prefixId) {
|
|
|
|
|
|
for (const model of models) {
|
|
|
|
|
|
model.id = `${prefixId}.${model.id}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-11 20:37:30 +00:00
|
|
|
|
const tags = apiConfig.tags;
|
|
|
|
|
|
if (tags) {
|
|
|
|
|
|
for (const model of models) {
|
|
|
|
|
|
model.tags = tags;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-12 09:17:30 +00:00
|
|
|
|
localModels = localModels.concat(models);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
models = models.concat(
|
|
|
|
|
|
localModels.map((model) => ({
|
|
|
|
|
|
...model,
|
|
|
|
|
|
name: model?.name ?? model?.id,
|
|
|
|
|
|
direct: true
|
|
|
|
|
|
}))
|
|
|
|
|
|
);
|
2025-02-12 09:32:49 +00:00
|
|
|
|
|
|
|
|
|
|
// Remove duplicates
|
|
|
|
|
|
const modelsMap = {};
|
|
|
|
|
|
for (const model of models) {
|
|
|
|
|
|
modelsMap[model.id] = model;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
models = Object.values(modelsMap);
|
2025-02-12 09:17:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-24 09:17:48 +00:00
|
|
|
|
return models;
|
2024-05-24 08:40:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-30 09:04:29 +00:00
|
|
|
|
type ChatCompletedForm = {
|
|
|
|
|
|
model: string;
|
|
|
|
|
|
messages: string[];
|
|
|
|
|
|
chat_id: string;
|
2024-08-07 14:33:24 +00:00
|
|
|
|
session_id: string;
|
2024-05-30 09:04:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const chatCompleted = async (token: string, body: ChatCompletedForm) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/chat/completed`, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify(body)
|
2024-06-09 22:00:38 +00:00
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-12 01:47:38 +00:00
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
type ChatActionForm = {
|
|
|
|
|
|
model: string;
|
|
|
|
|
|
messages: string[];
|
|
|
|
|
|
chat_id: string;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const chatAction = async (token: string, action_id: string, body: ChatActionForm) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/chat/actions/${action_id}`, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify(body)
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-09 22:00:38 +00:00
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-12-19 09:00:32 +00:00
|
|
|
|
export const stopTask = async (token: string, id: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/tasks/stop/${id}`, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-27 09:27:56 +00:00
|
|
|
|
export const getToolServerData = async (token: string, url: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${url}/openapi.json`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
|
openapi: res,
|
|
|
|
|
|
info: res.info,
|
|
|
|
|
|
specs: convertOpenApiToToolPayload(res)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
console.log(data);
|
|
|
|
|
|
return data;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const getToolServersData = async (servers: object[]) => {
|
|
|
|
|
|
return await Promise.all(
|
|
|
|
|
|
servers
|
|
|
|
|
|
.filter(async (server) => server?.config?.enable)
|
|
|
|
|
|
.map(async (server) => {
|
|
|
|
|
|
const data = await getToolServerData(server?.key, server?.url).catch((err) => {
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
|
|
const { openapi, info, specs } = data;
|
|
|
|
|
|
return {
|
|
|
|
|
|
url: server?.url,
|
|
|
|
|
|
openapi: openapi,
|
|
|
|
|
|
info: info,
|
|
|
|
|
|
specs: specs
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const executeToolServer = async (
|
|
|
|
|
|
token: string,
|
|
|
|
|
|
url: string,
|
|
|
|
|
|
name: string,
|
|
|
|
|
|
params: object,
|
|
|
|
|
|
serverData: { openapi: any; info: any; specs: any }
|
|
|
|
|
|
) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// Find the matching operationId in the OpenAPI specification
|
|
|
|
|
|
const matchingRoute = Object.entries(serverData.openapi.paths).find(([path, methods]) => {
|
|
|
|
|
|
return Object.entries(methods).some(
|
|
|
|
|
|
([method, operation]: any) => operation.operationId === name
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!matchingRoute) {
|
|
|
|
|
|
throw new Error(`No matching route found for operationId: ${name}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const [route, methods] = matchingRoute;
|
|
|
|
|
|
const methodEntry = Object.entries(methods).find(
|
|
|
|
|
|
([method, operation]: any) => operation.operationId === name
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!methodEntry) {
|
|
|
|
|
|
throw new Error(`No matching method found for operationId: ${name}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const [httpMethod, operation]: [string, any] = methodEntry;
|
|
|
|
|
|
|
|
|
|
|
|
// Replace path parameters in the URL
|
|
|
|
|
|
let finalUrl = `${url}${route}`;
|
|
|
|
|
|
if (operation.parameters) {
|
|
|
|
|
|
Object.entries(params).forEach(([key, value]) => {
|
|
|
|
|
|
finalUrl = finalUrl.replace(`{${key}}`, encodeURIComponent(value as string));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Headers and request options
|
|
|
|
|
|
const headers = {
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` }),
|
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let requestOptions: RequestInit = {
|
|
|
|
|
|
method: httpMethod.toUpperCase(),
|
|
|
|
|
|
headers
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Handle request body for POST, PUT, PATCH
|
|
|
|
|
|
if (['post', 'put', 'patch'].includes(httpMethod.toLowerCase()) && operation.requestBody) {
|
|
|
|
|
|
requestOptions.body = JSON.stringify(params);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Execute the request
|
|
|
|
|
|
const res = await fetch(finalUrl, requestOptions);
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
|
throw new Error(`HTTP error! Status: ${res.status}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await res.json();
|
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
|
error = err.message;
|
|
|
|
|
|
console.error('API Request Error:', error);
|
|
|
|
|
|
return { error };
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-06-09 22:00:38 +00:00
|
|
|
|
export const getTaskConfig = async (token: string = '') => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/config`, {
|
2024-06-09 22:00:38 +00:00
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const updateTaskConfig = async (token: string, config: object) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/config/update`, {
|
2024-06-09 22:00:38 +00:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify(config)
|
2024-05-30 09:04:29 +00:00
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-06-09 21:25:31 +00:00
|
|
|
|
export const generateTitle = async (
|
|
|
|
|
|
token: string = '',
|
|
|
|
|
|
model: string,
|
2024-10-21 11:24:17 +00:00
|
|
|
|
messages: string[],
|
2024-06-09 21:25:31 +00:00
|
|
|
|
chat_id?: string
|
|
|
|
|
|
) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/title/completions`, {
|
2024-06-09 21:25:31 +00:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
model: model,
|
2024-10-21 11:24:17 +00:00
|
|
|
|
messages: messages,
|
2024-06-09 21:25:31 +00:00
|
|
|
|
...(chat_id && { chat_id: chat_id })
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res?.choices[0]?.message?.content.replace(/["']/g, '') ?? 'New Chat';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-10-20 03:34:17 +00:00
|
|
|
|
export const generateTags = async (
|
|
|
|
|
|
token: string = '',
|
|
|
|
|
|
model: string,
|
|
|
|
|
|
messages: string,
|
|
|
|
|
|
chat_id?: string
|
|
|
|
|
|
) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/tags/completions`, {
|
2024-10-20 03:34:17 +00:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
model: model,
|
|
|
|
|
|
messages: messages,
|
|
|
|
|
|
...(chat_id && { chat_id: chat_id })
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// Step 1: Safely extract the response string
|
|
|
|
|
|
const response = res?.choices[0]?.message?.content ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
// Step 2: Attempt to fix common JSON format issues like single quotes
|
|
|
|
|
|
const sanitizedResponse = response.replace(/['‘’`]/g, '"'); // Convert single quotes to double quotes for valid JSON
|
|
|
|
|
|
|
|
|
|
|
|
// Step 3: Find the relevant JSON block within the response
|
|
|
|
|
|
const jsonStartIndex = sanitizedResponse.indexOf('{');
|
|
|
|
|
|
const jsonEndIndex = sanitizedResponse.lastIndexOf('}');
|
|
|
|
|
|
|
|
|
|
|
|
// Step 4: Check if we found a valid JSON block (with both `{` and `}`)
|
|
|
|
|
|
if (jsonStartIndex !== -1 && jsonEndIndex !== -1) {
|
|
|
|
|
|
const jsonResponse = sanitizedResponse.substring(jsonStartIndex, jsonEndIndex + 1);
|
|
|
|
|
|
|
|
|
|
|
|
// Step 5: Parse the JSON block
|
|
|
|
|
|
const parsed = JSON.parse(jsonResponse);
|
|
|
|
|
|
|
|
|
|
|
|
// Step 6: If there's a "tags" key, return the tags array; otherwise, return an empty array
|
|
|
|
|
|
if (parsed && parsed.tags) {
|
|
|
|
|
|
return Array.isArray(parsed.tags) ? parsed.tags : [];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If no valid JSON block found, return an empty array
|
|
|
|
|
|
return [];
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// Catch and safely return empty array on any parsing errors
|
|
|
|
|
|
console.error('Failed to parse response: ', e);
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-06-13 04:18:53 +00:00
|
|
|
|
export const generateEmoji = async (
|
|
|
|
|
|
token: string = '',
|
|
|
|
|
|
model: string,
|
|
|
|
|
|
prompt: string,
|
|
|
|
|
|
chat_id?: string
|
|
|
|
|
|
) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/emoji/completions`, {
|
2024-06-13 04:18:53 +00:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
model: model,
|
|
|
|
|
|
prompt: prompt,
|
|
|
|
|
|
...(chat_id && { chat_id: chat_id })
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-14 09:30:36 +00:00
|
|
|
|
const response = res?.choices[0]?.message?.content.replace(/["']/g, '') ?? null;
|
|
|
|
|
|
|
|
|
|
|
|
if (response) {
|
|
|
|
|
|
if (/\p{Extended_Pictographic}/u.test(response)) {
|
|
|
|
|
|
return response.match(/\p{Extended_Pictographic}/gu)[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
2024-06-13 04:18:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-11-19 10:24:32 +00:00
|
|
|
|
export const generateQueries = async (
|
2024-06-09 21:53:10 +00:00
|
|
|
|
token: string = '',
|
|
|
|
|
|
model: string,
|
|
|
|
|
|
messages: object[],
|
2024-11-19 10:24:32 +00:00
|
|
|
|
prompt: string,
|
|
|
|
|
|
type?: string = 'web_search'
|
2024-06-09 21:53:10 +00:00
|
|
|
|
) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/queries/completions`, {
|
2024-06-09 21:53:10 +00:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
model: model,
|
|
|
|
|
|
messages: messages,
|
2024-11-19 10:24:32 +00:00
|
|
|
|
prompt: prompt,
|
|
|
|
|
|
type: type
|
2024-06-09 21:53:10 +00:00
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-26 21:44:19 +00:00
|
|
|
|
// Step 1: Safely extract the response string
|
|
|
|
|
|
const response = res?.choices[0]?.message?.content ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2024-11-25 02:03:58 +00:00
|
|
|
|
const jsonStartIndex = response.indexOf('{');
|
|
|
|
|
|
const jsonEndIndex = response.lastIndexOf('}');
|
2024-11-19 10:24:32 +00:00
|
|
|
|
|
|
|
|
|
|
if (jsonStartIndex !== -1 && jsonEndIndex !== -1) {
|
2024-11-25 02:03:58 +00:00
|
|
|
|
const jsonResponse = response.substring(jsonStartIndex, jsonEndIndex + 1);
|
2024-11-19 10:24:32 +00:00
|
|
|
|
|
|
|
|
|
|
// Step 5: Parse the JSON block
|
|
|
|
|
|
const parsed = JSON.parse(jsonResponse);
|
|
|
|
|
|
|
|
|
|
|
|
// Step 6: If there's a "queries" key, return the queries array; otherwise, return an empty array
|
|
|
|
|
|
if (parsed && parsed.queries) {
|
|
|
|
|
|
return Array.isArray(parsed.queries) ? parsed.queries : [];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-27 04:03:06 +00:00
|
|
|
|
// If no valid JSON block found, return response as is
|
2024-11-26 21:44:19 +00:00
|
|
|
|
return [response];
|
2024-11-19 10:24:32 +00:00
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// Catch and safely return empty array on any parsing errors
|
|
|
|
|
|
console.error('Failed to parse response: ', e);
|
2024-11-26 21:44:19 +00:00
|
|
|
|
return [response];
|
2024-11-19 10:24:32 +00:00
|
|
|
|
}
|
2024-06-09 21:53:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-11-29 08:16:49 +00:00
|
|
|
|
export const generateAutoCompletion = async (
|
|
|
|
|
|
token: string = '',
|
|
|
|
|
|
model: string,
|
|
|
|
|
|
prompt: string,
|
2024-11-30 08:29:27 +00:00
|
|
|
|
messages?: object[],
|
2024-12-01 07:36:30 +00:00
|
|
|
|
type: string = 'search query'
|
2024-11-29 08:16:49 +00:00
|
|
|
|
) => {
|
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/auto/completions`, {
|
2024-11-29 08:16:49 +00:00
|
|
|
|
signal: controller.signal,
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
model: model,
|
|
|
|
|
|
prompt: prompt,
|
2024-11-30 08:29:27 +00:00
|
|
|
|
...(messages && { messages: messages }),
|
2024-11-29 09:02:32 +00:00
|
|
|
|
type: type,
|
2024-11-29 08:16:49 +00:00
|
|
|
|
stream: false
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2024-12-01 07:36:30 +00:00
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
2024-11-29 08:16:49 +00:00
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const response = res?.choices[0]?.message?.content ?? '';
|
2024-11-29 09:10:46 +00:00
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const jsonStartIndex = response.indexOf('{');
|
|
|
|
|
|
const jsonEndIndex = response.lastIndexOf('}');
|
|
|
|
|
|
|
|
|
|
|
|
if (jsonStartIndex !== -1 && jsonEndIndex !== -1) {
|
|
|
|
|
|
const jsonResponse = response.substring(jsonStartIndex, jsonEndIndex + 1);
|
|
|
|
|
|
|
|
|
|
|
|
// Step 5: Parse the JSON block
|
|
|
|
|
|
const parsed = JSON.parse(jsonResponse);
|
|
|
|
|
|
|
|
|
|
|
|
// Step 6: If there's a "queries" key, return the queries array; otherwise, return an empty array
|
|
|
|
|
|
if (parsed && parsed.text) {
|
|
|
|
|
|
return parsed.text;
|
|
|
|
|
|
} else {
|
2024-12-01 07:36:30 +00:00
|
|
|
|
return '';
|
2024-11-29 09:10:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If no valid JSON block found, return response as is
|
|
|
|
|
|
return response;
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
// Catch and safely return empty array on any parsing errors
|
|
|
|
|
|
console.error('Failed to parse response: ', e);
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
2024-11-29 08:16:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-08-18 18:59:59 +00:00
|
|
|
|
export const generateMoACompletion = async (
|
|
|
|
|
|
token: string = '',
|
|
|
|
|
|
model: string,
|
|
|
|
|
|
prompt: string,
|
|
|
|
|
|
responses: string[]
|
|
|
|
|
|
) => {
|
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/tasks/moa/completions`, {
|
2024-08-18 18:59:59 +00:00
|
|
|
|
signal: controller.signal,
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
model: model,
|
|
|
|
|
|
prompt: prompt,
|
|
|
|
|
|
responses: responses,
|
|
|
|
|
|
stream: true
|
|
|
|
|
|
})
|
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [res, controller];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-30 04:26:57 +00:00
|
|
|
|
export const getPipelinesList = async (token: string = '') => {
|
2024-05-28 19:04:19 +00:00
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/pipelines/list`, {
|
2024-05-30 04:26:57 +00:00
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let pipelines = res?.data ?? [];
|
|
|
|
|
|
return pipelines;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-06-05 20:57:48 +00:00
|
|
|
|
export const uploadPipeline = async (token: string, file: File, urlIdx: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
// Create a new FormData object to handle the file upload
|
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
|
formData.append('urlIdx', urlIdx);
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/pipelines/upload`, {
|
2024-06-05 20:57:48 +00:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
// 'Content-Type': 'multipart/form-data' is not needed as Fetch API will set it automatically
|
|
|
|
|
|
},
|
|
|
|
|
|
body: formData
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-30 05:03:22 +00:00
|
|
|
|
export const downloadPipeline = async (token: string, url: string, urlIdx: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/pipelines/add`, {
|
2024-05-30 05:03:22 +00:00
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
url: url,
|
|
|
|
|
|
urlIdx: urlIdx
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const deletePipeline = async (token: string, id: string, urlIdx: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-12-13 04:22:17 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/pipelines/delete`, {
|
2024-05-30 05:03:22 +00:00
|
|
|
|
method: 'DELETE',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
id: id,
|
|
|
|
|
|
urlIdx: urlIdx
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-30 04:26:57 +00:00
|
|
|
|
export const getPipelines = async (token: string, urlIdx?: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const searchParams = new URLSearchParams();
|
2024-05-30 05:41:51 +00:00
|
|
|
|
if (urlIdx !== undefined) {
|
2024-05-30 04:26:57 +00:00
|
|
|
|
searchParams.append('urlIdx', urlIdx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-25 20:07:55 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/v1/pipelines/?${searchParams.toString()}`, {
|
2024-05-28 19:04:19 +00:00
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let pipelines = res?.data ?? [];
|
|
|
|
|
|
return pipelines;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-30 05:18:27 +00:00
|
|
|
|
export const getPipelineValves = async (token: string, pipeline_id: string, urlIdx: string) => {
|
2024-05-28 19:32:49 +00:00
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-05-30 05:18:27 +00:00
|
|
|
|
const searchParams = new URLSearchParams();
|
2024-05-30 05:41:51 +00:00
|
|
|
|
if (urlIdx !== undefined) {
|
2024-05-30 05:18:27 +00:00
|
|
|
|
searchParams.append('urlIdx', urlIdx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
2024-12-13 04:22:17 +00:00
|
|
|
|
`${WEBUI_BASE_URL}/api/v1/pipelines/${pipeline_id}/valves?${searchParams.toString()}`,
|
2024-05-30 05:18:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
2024-05-28 19:32:49 +00:00
|
|
|
|
}
|
2024-05-30 05:18:27 +00:00
|
|
|
|
)
|
2024-05-28 19:32:49 +00:00
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-30 05:18:27 +00:00
|
|
|
|
export const getPipelineValvesSpec = async (token: string, pipeline_id: string, urlIdx: string) => {
|
2024-05-28 19:32:49 +00:00
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-05-30 05:18:27 +00:00
|
|
|
|
const searchParams = new URLSearchParams();
|
2024-05-30 05:41:51 +00:00
|
|
|
|
if (urlIdx !== undefined) {
|
2024-05-30 05:18:27 +00:00
|
|
|
|
searchParams.append('urlIdx', urlIdx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
2024-12-13 04:22:17 +00:00
|
|
|
|
`${WEBUI_BASE_URL}/api/v1/pipelines/${pipeline_id}/valves/spec?${searchParams.toString()}`,
|
2024-05-30 05:18:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
}
|
2024-05-28 19:32:49 +00:00
|
|
|
|
}
|
2024-05-30 05:18:27 +00:00
|
|
|
|
)
|
2024-05-28 19:32:49 +00:00
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const updatePipelineValves = async (
|
|
|
|
|
|
token: string = '',
|
|
|
|
|
|
pipeline_id: string,
|
2024-05-30 05:18:27 +00:00
|
|
|
|
valves: object,
|
|
|
|
|
|
urlIdx: string
|
2024-05-28 19:32:49 +00:00
|
|
|
|
) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-05-30 05:18:27 +00:00
|
|
|
|
const searchParams = new URLSearchParams();
|
2024-05-30 05:41:51 +00:00
|
|
|
|
if (urlIdx !== undefined) {
|
2024-05-30 05:18:27 +00:00
|
|
|
|
searchParams.append('urlIdx', urlIdx);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(
|
2024-12-13 04:22:17 +00:00
|
|
|
|
`${WEBUI_BASE_URL}/api/v1/pipelines/${pipeline_id}/valves/update?${searchParams.toString()}`,
|
2024-05-30 05:18:27 +00:00
|
|
|
|
{
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify(valves)
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
2024-05-28 19:32:49 +00:00
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
2024-05-28 20:05:31 +00:00
|
|
|
|
|
|
|
|
|
|
if ('detail' in err) {
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
}
|
2024-05-28 19:32:49 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-12-26 19:32:22 +00:00
|
|
|
|
export const getBackendConfig = async () => {
|
2023-12-26 11:28:30 +00:00
|
|
|
|
let error = null;
|
|
|
|
|
|
|
2024-02-22 02:12:01 +00:00
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/config`, {
|
2023-12-26 11:28:30 +00:00
|
|
|
|
method: 'GET',
|
2024-08-19 14:49:40 +00:00
|
|
|
|
credentials: 'include',
|
2023-12-26 11:28:30 +00:00
|
|
|
|
headers: {
|
2023-12-26 19:32:22 +00:00
|
|
|
|
'Content-Type': 'application/json'
|
2023-12-26 11:28:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
2023-12-26 19:32:22 +00:00
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
2023-12-26 11:28:30 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-02-25 19:55:15 +00:00
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-26 19:32:22 +00:00
|
|
|
|
return res;
|
2023-12-26 11:28:30 +00:00
|
|
|
|
};
|
2024-02-23 08:30:26 +00:00
|
|
|
|
|
|
|
|
|
|
export const getChangelog = async () => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/changelog`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-02-25 19:55:15 +00:00
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-02-03 23:20:27 +00:00
|
|
|
|
export const getVersionUpdates = async (token: string) => {
|
2024-02-25 19:55:15 +00:00
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
2025-02-03 23:20:27 +00:00
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
2024-02-25 19:55:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-23 08:30:26 +00:00
|
|
|
|
return res;
|
|
|
|
|
|
};
|
2024-03-10 05:29:04 +00:00
|
|
|
|
|
|
|
|
|
|
export const getModelFilterConfig = async (token: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/config/model/filter`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const updateModelFilterConfig = async (
|
|
|
|
|
|
token: string,
|
|
|
|
|
|
enabled: boolean,
|
|
|
|
|
|
models: string[]
|
|
|
|
|
|
) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/config/model/filter`, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
enabled: enabled,
|
|
|
|
|
|
models: models
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
2024-03-21 01:35:54 +00:00
|
|
|
|
|
|
|
|
|
|
export const getWebhookUrl = async (token: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/webhook`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res.url;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const updateWebhookUrl = async (token: string, url: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/webhook`, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
url: url
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res.url;
|
|
|
|
|
|
};
|
2024-05-09 15:49:54 +00:00
|
|
|
|
|
2024-05-26 16:23:24 +00:00
|
|
|
|
export const getCommunitySharingEnabledStatus = async (token: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/community_sharing`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const toggleCommunitySharingEnabledStatus = async (token: string) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/community_sharing/toggle`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err.detail;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-05-09 15:49:54 +00:00
|
|
|
|
export const getModelConfig = async (token: string): Promise<GlobalModelConfig> => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/config/models`, {
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res.models;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export interface ModelConfig {
|
|
|
|
|
|
id: string;
|
2024-05-19 10:46:24 +00:00
|
|
|
|
name: string;
|
2024-05-21 21:05:16 +00:00
|
|
|
|
meta: ModelMeta;
|
|
|
|
|
|
base_model_id?: string;
|
2024-05-19 10:46:24 +00:00
|
|
|
|
params: ModelParams;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-21 21:05:16 +00:00
|
|
|
|
export interface ModelMeta {
|
2024-05-09 15:49:54 +00:00
|
|
|
|
description?: string;
|
2024-05-25 07:44:21 +00:00
|
|
|
|
capabilities?: object;
|
2024-08-20 00:44:09 +00:00
|
|
|
|
profile_image_url?: string;
|
2024-05-09 15:49:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-21 21:05:16 +00:00
|
|
|
|
export interface ModelParams {}
|
|
|
|
|
|
|
2024-05-19 10:46:24 +00:00
|
|
|
|
export type GlobalModelConfig = ModelConfig[];
|
2024-05-09 15:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
export const updateModelConfig = async (token: string, config: GlobalModelConfig) => {
|
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/config/models`, {
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
|
},
|
2024-05-19 10:46:24 +00:00
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
|
models: config
|
|
|
|
|
|
})
|
2024-05-09 15:49:54 +00:00
|
|
|
|
})
|
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
|
|
return res.json();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
error = err;
|
|
|
|
|
|
return null;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
};
|