refac: gpt renamed to openai

This commit is contained in:
Timothy J. Baek 2024-01-17 14:23:16 -08:00
parent 1f66bbba98
commit f40147ce58
2 changed files with 51 additions and 51 deletions

View file

@ -21,7 +21,7 @@
import { WEB_UI_VERSION, WEBUI_API_BASE_URL } from '$lib/constants'; import { WEB_UI_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import { config, models, settings, user, chats } from '$lib/stores'; import { config, models, settings, user, chats } from '$lib/stores';
import { splitStream, getGravatarURL, getImportOrigin, convertGptChats } from '$lib/utils'; import { splitStream, getGravatarURL, getImportOrigin, convertOpenAIChats } from '$lib/utils';
import Advanced from './Settings/Advanced.svelte'; import Advanced from './Settings/Advanced.svelte';
import Modal from '../common/Modal.svelte'; import Modal from '../common/Modal.svelte';
@ -132,11 +132,11 @@
reader.onload = (event) => { reader.onload = (event) => {
let chats = JSON.parse(event.target.result); let chats = JSON.parse(event.target.result);
console.log(chats); console.log(chats);
if (getImportOrigin(chats) == 'gpt') { if (getImportOrigin(chats) == 'openai') {
try { try {
chats = convertGptChats(chats); chats = convertOpenAIChats(chats);
} catch (error) { } catch (error) {
console.log("Unable to import chats:", error); console.log('Unable to import chats:', error);
} }
} }
importChats(chats); importChats(chats);

View file

@ -196,67 +196,67 @@ 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]) { if ('mapping' in _chats[0]) {
return 'gpt'; return 'openai';
} }
return 'webui'; 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) { for (let message_id in mapping) {
const message = mapping[message_id]; 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, id: message_id,
"parentId": messages.length > 0 ? message["parent"] : null, parentId: messages.length > 0 ? message['parent'] : null,
"childrenIds": message["children"] || [], childrenIds: message['children'] || [],
"role": message["message"]?.["author"]?.["role"] !== "user" ? "assistant" : "user", role: message['message']?.['author']?.['role'] !== 'user' ? 'assistant' : 'user',
"content": message["message"]?.["content"]?.['parts']?.[0] || "", content: message['message']?.['content']?.['parts']?.[0] || '',
"model": '', model: '',
"done": true, done: true,
"context": null, context: null
} };
messages.push(new_chat) 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": { history: {
"currentId": currentId, currentId: currentId,
"messages": history, // Need to convert this to not a list and instead a json object messages: history // Need to convert this to not a list and instead a json object
}, },
"models": [""], models: [''],
"messages": messages, messages: messages,
"options": {}, options: {},
"timestamp": convo["create_time"], timestamp: convo['create_time'],
"title": convo["title"], title: convo['title']
} };
return chat; 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 = []; const chats = [];
for (let convo of _chats) { for (let convo of _chats) {
const chat = { const chat = {
"id": convo["id"], id: convo['id'],
"user_id": '', user_id: '',
"title": convo["title"], title: convo['title'],
"chat": convertGptMessages(convo), chat: convertOpenAIMessages(convo),
"timestamp": convo["timestamp"], timestamp: convo['timestamp']
} };
chats.push(chat) chats.push(chat);
} }
return chats; return chats;
} };