open-webui/src/lib/apis/configs/index.ts

405 lines
7.5 KiB
TypeScript
Raw Normal View History

2024-01-03 00:48:10 +00:00
import { WEBUI_API_BASE_URL } from '$lib/constants';
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.error(err);
2024-09-03 19:16:07 +00:00
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.error(err);
2024-09-03 19:16:07 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
2025-02-12 07:12:00 +00:00
export const getDirectConnectionsConfig = async (token: string) => {
2025-02-12 06:29:45 +00:00
let error = null;
2025-02-12 07:12:00 +00:00
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/direct_connections`, {
2025-02-12 06:29:45 +00:00
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.error(err);
2025-02-12 06:29:45 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
2025-02-12 07:12:00 +00:00
export const setDirectConnectionsConfig = async (token: string, config: object) => {
2025-02-12 06:29:45 +00:00
let error = null;
2025-02-12 07:12:00 +00:00
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/direct_connections`, {
2025-02-12 06:29:45 +00:00
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.error(err);
2025-02-12 06:29:45 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
2025-04-05 10:05:52 +00:00
export const getToolServerConnections = async (token: string) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/tool_servers`, {
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.error(err);
2025-04-05 10:05:52 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
export const setToolServerConnections = async (token: string, connections: object) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/tool_servers`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
...connections
})
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.error(err);
2025-04-05 10:05:52 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
export const verifyToolServerConnection = async (token: string, connection: object) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/tool_servers/verify`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
},
body: JSON.stringify({
...connection
})
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.error(err);
2025-04-05 10:05:52 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
2025-02-18 00:25:50 +00:00
export const getCodeExecutionConfig = async (token: string) => {
2025-02-10 10:25:02 +00:00
let error = null;
2025-02-18 00:25:50 +00:00
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/code_execution`, {
2025-02-10 10:25:02 +00:00
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.error(err);
2025-02-10 10:25:02 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
2025-02-18 00:25:50 +00:00
export const setCodeExecutionConfig = async (token: string, config: object) => {
2025-02-10 10:25:02 +00:00
let error = null;
2025-02-18 00:25:50 +00:00
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/code_execution`, {
2025-02-10 10:25:02 +00:00
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.error(err);
2025-02-10 10:25:02 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
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.error(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;
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({
...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.error(err);
2024-01-03 00:48:10 +00:00
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
export const setDefaultPromptSuggestions = async (token: string, promptSuggestions: string) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/suggestions`, {
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.error(err);
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};
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.error(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.error(err);
error = err.detail;
return null;
});
if (error) {
throw error;
}
return res;
};