2024-02-22 02:12:01 +00:00
|
|
|
import { WEBUI_BASE_URL } from '$lib/constants';
|
2023-12-26 19:32:22 +00:00
|
|
|
|
2024-05-24 08:40:48 +00:00
|
|
|
export const getModels = async (token: string = '') => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/models`, {
|
|
|
|
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?.data ?? [];
|
|
|
|
};
|
|
|
|
|
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',
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getVersionUpdates = async () => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, {
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
vision_capable?: boolean;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
};
|