|
@@ -195,68 +195,68 @@ export const calculateSHA256 = async (file) => {
|
|
|
|
|
|
export const getImportOrigin = (_chats) => {
|
|
export const getImportOrigin = (_chats) => {
|
|
// Check what external service chat imports are from
|
|
// Check what external service chat imports are from
|
|
- if ('mapping' in _chats[0]) {
|
|
|
|
- return 'gpt';
|
|
|
|
- }
|
|
|
|
- return 'webui';
|
|
|
|
-}
|
|
|
|
|
|
+ if ('mapping' in _chats[0]) {
|
|
|
|
+ return 'openai';
|
|
|
|
+ }
|
|
|
|
+ return 'webui';
|
|
|
|
+};
|
|
|
|
|
|
-const convertGptMessages = (convo) => {
|
|
|
|
|
|
+const convertOpenAIMessages = (convo) => {
|
|
// Parse OpenAI chat messages and create chat dictionary for creating new chats
|
|
// Parse OpenAI chat messages and create chat dictionary for creating new chats
|
|
- const mapping = convo["mapping"];
|
|
|
|
|
|
+ const mapping = convo['mapping'];
|
|
const messages = [];
|
|
const messages = [];
|
|
- let currentId = "";
|
|
|
|
|
|
+ let currentId = '';
|
|
|
|
|
|
- for (let message_id in mapping) {
|
|
|
|
- const message = mapping[message_id];
|
|
|
|
|
|
+ for (let message_id in mapping) {
|
|
|
|
+ const message = mapping[message_id];
|
|
currentId = message_id;
|
|
currentId = message_id;
|
|
- if (message["message"] == null || message["message"]["content"]["parts"][0] == "") {
|
|
|
|
|
|
+ if (message['message'] == null || message['message']['content']['parts'][0] == '') {
|
|
// Skip chat messages with no content
|
|
// Skip chat messages with no content
|
|
continue;
|
|
continue;
|
|
} else {
|
|
} else {
|
|
const new_chat = {
|
|
const new_chat = {
|
|
- "id": message_id,
|
|
|
|
- "parentId": messages.length > 0 ? message["parent"] : null,
|
|
|
|
- "childrenIds": message["children"] || [],
|
|
|
|
- "role": message["message"]?.["author"]?.["role"] !== "user" ? "assistant" : "user",
|
|
|
|
- "content": message["message"]?.["content"]?.['parts']?.[0] || "",
|
|
|
|
- "model": '',
|
|
|
|
- "done": true,
|
|
|
|
- "context": null,
|
|
|
|
- }
|
|
|
|
- messages.push(new_chat)
|
|
|
|
|
|
+ id: message_id,
|
|
|
|
+ parentId: messages.length > 0 ? message['parent'] : null,
|
|
|
|
+ childrenIds: message['children'] || [],
|
|
|
|
+ role: message['message']?.['author']?.['role'] !== 'user' ? 'assistant' : 'user',
|
|
|
|
+ content: message['message']?.['content']?.['parts']?.[0] || '',
|
|
|
|
+ model: '',
|
|
|
|
+ done: true,
|
|
|
|
+ context: null
|
|
|
|
+ };
|
|
|
|
+ messages.push(new_chat);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
let history = {};
|
|
let history = {};
|
|
- messages.forEach(obj => history[obj.id] = obj);
|
|
|
|
|
|
+ messages.forEach((obj) => (history[obj.id] = obj));
|
|
|
|
|
|
const chat = {
|
|
const chat = {
|
|
- "history": {
|
|
|
|
- "currentId": currentId,
|
|
|
|
- "messages": history, // Need to convert this to not a list and instead a json object
|
|
|
|
|
|
+ history: {
|
|
|
|
+ currentId: currentId,
|
|
|
|
+ messages: history // Need to convert this to not a list and instead a json object
|
|
},
|
|
},
|
|
- "models": [""],
|
|
|
|
- "messages": messages,
|
|
|
|
- "options": {},
|
|
|
|
- "timestamp": convo["create_time"],
|
|
|
|
- "title": convo["title"],
|
|
|
|
- }
|
|
|
|
- return chat;
|
|
|
|
-}
|
|
|
|
|
|
+ models: [''],
|
|
|
|
+ messages: messages,
|
|
|
|
+ options: {},
|
|
|
|
+ timestamp: convo['create_time'],
|
|
|
|
+ title: convo['title']
|
|
|
|
+ };
|
|
|
|
+ return chat;
|
|
|
|
+};
|
|
|
|
|
|
-export const convertGptChats = (_chats) => {
|
|
|
|
|
|
+export const convertOpenAIChats = (_chats) => {
|
|
// Create a list of dictionaries with each conversation from import
|
|
// Create a list of dictionaries with each conversation from import
|
|
- const chats = [];
|
|
|
|
- for (let convo of _chats) {
|
|
|
|
- const chat = {
|
|
|
|
- "id": convo["id"],
|
|
|
|
- "user_id": '',
|
|
|
|
- "title": convo["title"],
|
|
|
|
- "chat": convertGptMessages(convo),
|
|
|
|
- "timestamp": convo["timestamp"],
|
|
|
|
- }
|
|
|
|
- chats.push(chat)
|
|
|
|
|
|
+ const chats = [];
|
|
|
|
+ for (let convo of _chats) {
|
|
|
|
+ const chat = {
|
|
|
|
+ id: convo['id'],
|
|
|
|
+ user_id: '',
|
|
|
|
+ title: convo['title'],
|
|
|
|
+ chat: convertOpenAIMessages(convo),
|
|
|
|
+ timestamp: convo['timestamp']
|
|
|
|
+ };
|
|
|
|
+ chats.push(chat);
|
|
}
|
|
}
|
|
- return chats;
|
|
|
|
-}
|
|
|
|
|
|
+ return chats;
|
|
|
|
+};
|