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

πŸ› fix: disregard remoteModelCards when showModelFetcher is disabled #4644

Merged
merged 1 commit into from
Nov 9, 2024
Merged
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
23 changes: 12 additions & 11 deletions src/store/user/slices/modelList/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { StateCreator } from 'zustand/vanilla';
import { DEFAULT_MODEL_PROVIDER_LIST } from '@/config/modelProviders';
import { ModelProvider } from '@/libs/agent-runtime';
import { UserStore } from '@/store/user';
import { ChatModelCard } from '@/types/llm';
import {
import type { ChatModelCard, ModelProviderCard } from '@/types/llm';
import type {
GlobalLLMProviderKey,
UserKeyVaults,
UserModelProviderConfig,
Expand Down Expand Up @@ -79,20 +79,21 @@ export const createModelListSlice: StateCreator<
* 3 - default model cards
*/

// eslint-disable-next-line unicorn/consistent-function-scoping
const mergeModels = (provider: GlobalLLMProviderKey, defaultChatModels: ChatModelCard[]) => {
const mergeModels = (providerKey: GlobalLLMProviderKey, providerCard: ModelProviderCard) => {
// if the chat model is config in the server side, use the server side model cards
const serverChatModels = modelProviderSelectors.serverProviderModelCards(provider)(get());
const remoteChatModels = modelProviderSelectors.remoteProviderModelCards(provider)(get());
const serverChatModels = modelProviderSelectors.serverProviderModelCards(providerKey)(get());
const remoteChatModels = providerCard.modelList?.showModelFetcher
? modelProviderSelectors.remoteProviderModelCards(providerKey)(get())
: undefined;

return serverChatModels ?? remoteChatModels ?? defaultChatModels;
return serverChatModels ?? remoteChatModels ?? providerCard.chatModels;
};

const defaultModelProviderList = produce(DEFAULT_MODEL_PROVIDER_LIST, (draft) => {
Object.values(ModelProvider).forEach((id) =>{
const provider = draft.find((d) => d.id === id);
if (provider) provider.chatModels = mergeModels(id as any, provider.chatModels);
})
Object.values(ModelProvider).forEach((id) => {
const provider = draft.find((d) => d.id === id);
if (provider) provider.chatModels = mergeModels(id as any, provider);
});
});

set({ defaultModelProviderList }, false, `refreshDefaultModelList - ${params?.trigger}`);
Expand Down
Loading