Skip to content

Commit

Permalink
♻️ refactor: 优化新会话的创建逻辑 session
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jul 24, 2023
1 parent a26c199 commit d70f22d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/store/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export const useSessionStore = create<SessionStore>()(

export * from './selectors';
export { initialLobeAgentConfig } from './slices/agentConfig';
export { initLobeSession } from './slices/session';
export type { SessionStore } from './store';
21 changes: 6 additions & 15 deletions src/store/session/slices/session/action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { merge } from 'lodash-es';
import Router from 'next/router';
import { StateCreator } from 'zustand/vanilla';

import { SessionStore } from '@/store/session';
import { LanguageModel } from '@/types/llm';
import { LobeAgentSession, LobeSessionType } from '@/types/session';
import { SessionStore, initLobeSession } from '@/store/session';
import { LobeAgentSession } from '@/types/session';
import { uuid } from '@/utils/uuid';

import { SessionDispatch, sessionsReducer } from './reducers/session';
Expand Down Expand Up @@ -58,21 +58,12 @@ export const createSessionSlice: StateCreator<

const timestamp = Date.now();

const newSession: LobeAgentSession = {
chats: {},
config: {
model: LanguageModel.GPT3_5,
params: {
temperature: 0.6,
},
systemRole: '',
},
// TODO: 等 settings 里的 defaultAgent 都改好以后,做个合并即可
const newSession: LobeAgentSession = merge({}, initLobeSession, {
createAt: timestamp,
id: uuid(),
meta: {},
type: LobeSessionType.Agent,
updateAt: timestamp,
};
});

dispatchSession({ session: newSession, type: 'addSession' });

Expand Down

0 comments on commit d70f22d

Please sign in to comment.