Skip to content

Commit

Permalink
Import Conversation: update signature
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Oct 17, 2023
1 parent 3f63d03 commit c46741f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/apps/chat/trade/ImportChats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function ImportConversations(props: { onClose: () => void }) {
// import conversations (warning - will overwrite things)
for (let conversation of [...outcome.conversations].reverse()) {
if (conversation.success)
useChatStore.getState().importConversation(conversation.conversation);
useChatStore.getState().importConversation(conversation.conversation, false);
}

// show the outcome of the import
Expand Down Expand Up @@ -109,7 +109,7 @@ export function ImportConversations(props: { onClose: () => void }) {
// outcome
const success = conversation.messages.length >= 1;
if (success) {
useChatStore.getState().importConversation(conversation);
useChatStore.getState().importConversation(conversation, false);
outcome.conversations.push({ success: true, fileName: 'chatgpt', conversation });
} else
outcome.conversations.push({ success: false, fileName: 'chatgpt', error: `Empty conversation` });
Expand Down
12 changes: 10 additions & 2 deletions src/common/state/store-chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ interface ChatActions {
// store setters
createConversation: () => void;
duplicateConversation: (conversationId: string) => void;
importConversation: (conversation: DConversation) => void;
importConversation: (conversation: DConversation, preventClash: boolean) => void;
deleteConversation: (conversationId: string) => void;
deleteAllConversations: () => void;
setActiveConversationId: (conversationId: string) => void;
Expand Down Expand Up @@ -193,7 +193,15 @@ export const useChatStore = create<ChatState & ChatActions>()(devtools(
};
}),

importConversation: (conversation: DConversation) => {
importConversation: (conversation: DConversation, preventClash) => {
// if we're importing a conversation with the same id as an existing one, we need to change the id
if (preventClash) {
const exists = get().conversations.some(c => c.id === conversation.id);
if (exists) {
conversation.id = uuidv4();
console.warn('Conversation ID clash, changing ID to', conversation.id);
}
}
get().deleteConversation(conversation.id);
set(state => {
conversation.tokenCount = updateTokenCounts(conversation.messages, true, 'importConversation');
Expand Down

1 comment on commit c46741f

@vercel
Copy link

@vercel vercel bot commented on c46741f Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

big-agi – ./

big-agi-git-main-enricoros.vercel.app
big-agi-enricoros.vercel.app
get.big-agi.com

Please sign in to comment.