Skip to content

Commit

Permalink
Merge pull request #5432 from ConnectAI-E/Feature-fork
Browse files Browse the repository at this point in the history
feat fork
  • Loading branch information
Dogtiti committed Sep 18, 2024
2 parents b4dc4d3 + fd47bc1 commit 9ddd5a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface ChatCommands {
next?: Command;
prev?: Command;
clear?: Command;
fork?: Command;
del?: Command;
}

Expand Down
1 change: 1 addition & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ function _Chat() {
chatStore.updateCurrentSession(
(session) => (session.clearContextIndex = session.messages.length),
),
fork: () => chatStore.forkSession(),
del: () => chatStore.deleteSession(chatStore.currentSessionIndex),
});

Expand Down
1 change: 1 addition & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const cn = {
next: "下一个聊天",
prev: "上一个聊天",
clear: "清除上下文",
fork: "复制聊天",
del: "删除聊天",
},
InputActions: {
Expand Down
1 change: 1 addition & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const en: LocaleType = {
next: "Next Chat",
prev: "Previous Chat",
clear: "Clear Context",
fork: "Copy Chat",
del: "Delete Chat",
},
InputActions: {
Expand Down
22 changes: 22 additions & 0 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ export const useChatStore = createPersistStore(
}

const methods = {
forkSession() {
// 获取当前会话
const currentSession = get().currentSession();
if (!currentSession) return;

const newSession = createEmptySession();

newSession.topic = currentSession.topic;
newSession.messages = [...currentSession.messages];
newSession.mask = {
...currentSession.mask,
modelConfig: {
...currentSession.mask.modelConfig,
},
};

set((state) => ({
currentSessionIndex: 0,
sessions: [newSession, ...state.sessions],
}));
},

clearSessions() {
set(() => ({
sessions: [createEmptySession()],
Expand Down

0 comments on commit 9ddd5a0

Please sign in to comment.