Skip to content

Commit

Permalink
Merge pull request #169 from lobehub/feat/video-and-chat
Browse files Browse the repository at this point in the history
Feat/video and chat
  • Loading branch information
rdmclin2 authored Nov 23, 2024
2 parents 2dffc44 + 1043d19 commit 2a57a8d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/features/DebugUI/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,9 @@ const settings = {
backgroundEffect: 'glow',
languageModel: {
openAI: {
model: 'gpt-4o',
fetchOnClient: true,
apiKey: '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',
endpoint: 'https://openrouter.ai/api/v1',
},
},
},
Expand Down
6 changes: 5 additions & 1 deletion src/layout/StoreHydration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { memo, useEffect } from 'react';
import { AGENT_STORAGE_KEY, useAgentStore } from '@/store/agent';
import { DANCE_STORAGE_KEY } from '@/store/dance';
import { SESSION_STORAGE_KEY } from '@/store/session';
import { SETTING_STORAGE_KEY } from '@/store/setting';
import { SETTING_STORAGE_KEY, useSettingStore } from '@/store/setting';
import { vidolStorage } from '@/utils/storage';

const MIGRATION_KEY = 'MIGRATE_TO_INDEXED_DB';
Expand All @@ -33,11 +33,15 @@ const migrate = async () => {
const StoreHydration = () => {
const router = useRouter();

const refreshDefaultModelProviderList = useSettingStore((s) => s.refreshDefaultModelProviderList);

useEffect(() => {
// refs: https://github.com/pmndrs/zustand/blob/main/docs/integrations/persisting-store-data.md#hashydrated
migrate().then(() => {
useAgentStore.persist.rehydrate();
});

refreshDefaultModelProviderList();
}, []);

useEffect(() => {
Expand Down
31 changes: 30 additions & 1 deletion src/store/setting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { shallow } from 'zustand/shallow';
import { createWithEqualityFn } from 'zustand/traditional';
import { StateCreator } from 'zustand/vanilla';

import { ModelProvider } from '@/libs/agent-runtime/types/type';
import { ModelListAction, createModelListSlice } from '@/store/setting/slices/modelList';
import createTouchStore, { TouchStore } from '@/store/setting/slices/touch';
import { BackgroundEffect, Config } from '@/types/config';
Expand Down Expand Up @@ -118,7 +119,35 @@ const createStore: StateCreator<SettingStore, [['zustand/devtools', never]], [],
const persistOptions: PersistOptions<SettingStore> = {
name: SETTING_STORAGE_KEY, // name of the item in the storage (must be unique)
storage: createJSONStorage(() => vidolStorage),
version: 0,
version: 1,
migrate: (persistedState: unknown, version: number): SettingStore => {
if (version === 0) {
const state = persistedState as SettingStore;
if (state.config.languageModel) {
state.config.languageModel = {
...state.config.languageModel,
[ModelProvider.OpenAI]: {
//@ts-ignore
...state.config.languageModel['openAI'],
},
};
state.config.languageModel[ModelProvider.OpenAI]!.fetchOnClient =
//@ts-ignore
state.config.languageModel['openAI']!.fetchOnClient;
state.config.keyVaults = {
...state.config.keyVaults,
[ModelProvider.OpenAI]: {
//@ts-ignore
apiKey: state.config.languageModel['openAI']!.apiKey,
//@ts-ignore
baseURL: state.config.languageModel['openAI']!.endpoint,
},
};
}
return state;
}
return persistedState as SettingStore;
},
};

export const useSettingStore = createWithEqualityFn<SettingStore>()(
Expand Down

0 comments on commit 2a57a8d

Please sign in to comment.