Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/video and chat #169

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading