2023-12-26 11:28:30 +00:00
|
|
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
|
|
|
|
|
|
|
export const createNewChat = async (token: string, chat: object) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/new`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
chat: chat
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2023-12-26 20:50:52 +00:00
|
|
|
export const getChatList = async (token: string = '') => {
|
2023-12-26 11:28:30 +00:00
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
}
|
2023-12-27 06:10:22 +00:00
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2024-04-20 23:24:18 +00:00
|
|
|
export const getArchivedChatList = async (token: string = '') => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/archived`, {
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2023-12-27 06:10:22 +00:00
|
|
|
export const getAllChats = async (token: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/all`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
}
|
2024-02-04 09:07:18 +00:00
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getAllUserChats = async (token: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/all/db`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
}
|
2024-01-18 10:55:25 +00:00
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getAllChatTags = async (token: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/tags/all`, {
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getChatListByTagName = async (token: string = '', tagName: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/tags/tag/${tagName}`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
}
|
2023-12-26 11:28:30 +00:00
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getChatById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}`, {
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2024-03-31 21:03:28 +00:00
|
|
|
export const getChatByShareId = async (token: string, share_id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/share/${share_id}`, {
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const shareChatById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/share`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
}
|
2024-04-20 22:03:39 +00:00
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const archiveChatById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/archive`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
}
|
2024-03-31 21:03:28 +00:00
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteSharedChatById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
2024-04-02 14:04:04 +00:00
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/share`, {
|
2024-03-31 21:03:28 +00:00
|
|
|
method: 'DELETE',
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2023-12-26 11:28:30 +00:00
|
|
|
export const updateChatById = async (token: string, id: string, chat: object) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
chat: chat
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteChatById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2024-02-14 09:17:43 +00:00
|
|
|
error = err.detail;
|
2023-12-26 11:28:30 +00:00
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
2023-12-30 08:15:37 +00:00
|
|
|
|
2024-01-18 09:04:24 +00:00
|
|
|
export const getTagsById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/tags`, {
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const addTagById = async (token: string, id: string, tagName: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/tags`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
tag_name: tagName,
|
|
|
|
chat_id: id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteTagById = async (token: string, id: string, tagName: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/tags`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
...(token && { authorization: `Bearer ${token}` })
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
tag_name: tagName,
|
|
|
|
chat_id: id
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
export const deleteTagsById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/${id}/tags/all`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2023-12-30 08:15:37 +00:00
|
|
|
export const deleteAllChats = async (token: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/chats/`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2024-03-02 08:07:50 +00:00
|
|
|
error = err.detail;
|
2023-12-30 08:15:37 +00:00
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|