2024-01-03 00:48:10 +00:00
|
|
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
2024-05-26 19:18:43 +00:00
|
|
|
import type { Banner } from '$lib/types';
|
2024-01-03 00:48:10 +00:00
|
|
|
|
2024-09-03 19:16:07 +00:00
|
|
|
export const importConfig = async (token: string, config) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/import`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
config: config
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const exportConfig = async (token: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/export`, {
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-10 10:25:02 +00:00
|
|
|
export const getCodeInterpreterConfig = async (token: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/code_interpreter`, {
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setCodeInterpreterConfig = async (token: string, config: object) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/code_interpreter`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
...config
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.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-11-26 08:55:58 +00:00
|
|
|
export const getModelsConfig = async (token: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/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.detail;
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setModelsConfig = async (token: string, config: object) => {
|
2024-01-03 00:48:10 +00:00
|
|
|
let error = null;
|
|
|
|
|
|
2024-11-26 08:55:58 +00:00
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/models`, {
|
2024-01-03 01:26:19 +00:00
|
|
|
method: 'POST',
|
2024-01-03 00:48:10 +00:00
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
2024-11-26 08:55:58 +00:00
|
|
|
...config
|
2024-01-03 00:48:10 +00:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.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-01-23 05:53:13 +00:00
|
|
|
|
|
|
|
|
export const setDefaultPromptSuggestions = async (token: string, promptSuggestions: string) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
2024-11-26 08:55:58 +00:00
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/suggestions`, {
|
2024-01-23 05:53:13 +00:00
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
suggestions: promptSuggestions
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.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-26 19:18:43 +00:00
|
|
|
|
|
|
|
|
export const getBanners = async (token: string): Promise<Banner[]> => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/banners`, {
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setBanners = async (token: string, banners: Banner[]) => {
|
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/banners`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
banners: banners
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.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;
|
|
|
|
|
};
|