♻️ refactor: 优化新会话的创建逻辑 session

This commit is contained in:
arvinxx
2023-07-25 00:59:21 +08:00
parent a26c199116
commit d70f22d6b6
2 changed files with 7 additions and 15 deletions

View File

@@ -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';

View File

@@ -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';
@@ -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' });