@lobehub/chat 0.147.1 β 0.147.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/app/settings/llm/Azure/index.tsx +1 -1
- package/src/app/settings/llm/components/ProviderConfig/index.tsx +1 -1
- package/src/app/settings/llm/components/ProviderModelList/CustomModelOption.tsx +1 -1
- package/src/app/settings/llm/components/ProviderModelList/ModelConfigModal.tsx +1 -1
- package/src/app/settings/llm/components/ProviderModelList/ModelFetcher.tsx +3 -3
- package/src/app/settings/llm/components/ProviderModelList/index.tsx +2 -2
- package/src/features/AgentSetting/AgentConfig/ModelSelect.tsx +1 -1
- package/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx +2 -2
- package/src/features/ModelSwitchPanel/index.tsx +1 -1
- package/src/services/_auth.ts +5 -3
- package/src/services/_header.ts +3 -4
- package/src/services/chat.ts +1 -1
- package/src/services/ollama.ts +3 -2
- package/src/store/global/slices/settings/actions/llm.test.ts +1 -1
- package/src/store/global/slices/settings/actions/llm.ts +2 -2
- package/src/store/global/slices/settings/selectors/modelConfig.test.ts +35 -14
- package/src/store/global/slices/settings/selectors/modelConfig.ts +55 -118
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.147.2](https://github.com/lobehub/lobe-chat/compare/v0.147.1...v0.147.2)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-04-11**</sup>
|
|
8
|
+
|
|
9
|
+
#### π Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix custom model not display correctly.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix custom model not display correctly, closes [#1972](https://github.com/lobehub/lobe-chat/issues/1972) ([5d7cae9](https://github.com/lobehub/lobe-chat/commit/5d7cae9))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
### [Version 0.147.1](https://github.com/lobehub/lobe-chat/compare/v0.147.0...v0.147.1)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2024-04-11**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.147.
|
|
3
|
+
"version": "0.147.2",
|
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -34,7 +34,7 @@ const AzureOpenAIProvider = memo(() => {
|
|
|
34
34
|
|
|
35
35
|
// Get the first model card's deployment name as the check model
|
|
36
36
|
const checkModel = useGlobalStore((s) => {
|
|
37
|
-
const chatModelCards = modelConfigSelectors.
|
|
37
|
+
const chatModelCards = modelConfigSelectors.getModelCardsByProviderId(providerKey)(s);
|
|
38
38
|
|
|
39
39
|
if (chatModelCards.length > 0) {
|
|
40
40
|
return chatModelCards[0].deploymentName;
|
|
@@ -54,7 +54,7 @@ const ProviderConfig = memo<ProviderConfigProps>(
|
|
|
54
54
|
const [toggleProviderEnabled, setSettings, enabled] = useGlobalStore((s) => [
|
|
55
55
|
s.toggleProviderEnabled,
|
|
56
56
|
s.setSettings,
|
|
57
|
-
modelConfigSelectors.
|
|
57
|
+
modelConfigSelectors.isProviderEnabled(provider)(s),
|
|
58
58
|
]);
|
|
59
59
|
|
|
60
60
|
useSyncSettings(form);
|
|
@@ -29,7 +29,7 @@ const CustomModelOption = memo<CustomModelOptionProps>(({ id, provider }) => {
|
|
|
29
29
|
s.removeEnabledModels,
|
|
30
30
|
]);
|
|
31
31
|
const modelCard = useGlobalStore(
|
|
32
|
-
modelConfigSelectors.
|
|
32
|
+
modelConfigSelectors.getCustomModelCard({ id, provider }),
|
|
33
33
|
isEqual,
|
|
34
34
|
);
|
|
35
35
|
|
|
@@ -27,7 +27,7 @@ const ModelConfigModal = memo<ModelConfigModalProps>(({ showAzureDeployName, pro
|
|
|
27
27
|
]);
|
|
28
28
|
|
|
29
29
|
const modelCard = useGlobalStore(
|
|
30
|
-
modelConfigSelectors.
|
|
30
|
+
modelConfigSelectors.getCustomModelCard({ id, provider: editingProvider }),
|
|
31
31
|
isEqual,
|
|
32
32
|
);
|
|
33
33
|
|
|
@@ -36,12 +36,12 @@ const ModelFetcher = memo<ModelFetcherProps>(({ provider }) => {
|
|
|
36
36
|
s.useFetchProviderModelList,
|
|
37
37
|
s.setModelProviderConfig,
|
|
38
38
|
]);
|
|
39
|
-
const enabledAutoFetch = useGlobalStore(modelConfigSelectors.
|
|
39
|
+
const enabledAutoFetch = useGlobalStore(modelConfigSelectors.isAutoFetchModelsEnabled(provider));
|
|
40
40
|
const latestFetchTime = useGlobalStore(
|
|
41
|
-
(s) => modelConfigSelectors.
|
|
41
|
+
(s) => modelConfigSelectors.getConfigByProviderId(provider)(s)?.latestFetchTime,
|
|
42
42
|
);
|
|
43
43
|
const totalModels = useGlobalStore(
|
|
44
|
-
(s) => modelConfigSelectors.
|
|
44
|
+
(s) => modelConfigSelectors.getModelCardsByProviderId(provider)(s).length,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
const { mutate, isValidating } = useFetchProviderModelList(provider, enabledAutoFetch);
|
|
@@ -51,7 +51,7 @@ const ProviderModelListSelect = memo<CustomModelSelectProps>(
|
|
|
51
51
|
]);
|
|
52
52
|
|
|
53
53
|
const chatModelCards = useGlobalStore(
|
|
54
|
-
modelConfigSelectors.
|
|
54
|
+
modelConfigSelectors.getModelCardsByProviderId(provider),
|
|
55
55
|
isEqual,
|
|
56
56
|
);
|
|
57
57
|
|
|
@@ -60,7 +60,7 @@ const ProviderModelListSelect = memo<CustomModelSelectProps>(
|
|
|
60
60
|
isEqual,
|
|
61
61
|
);
|
|
62
62
|
const enabledModels = useGlobalStore(
|
|
63
|
-
modelConfigSelectors.
|
|
63
|
+
modelConfigSelectors.getEnableModelsByProviderId(provider),
|
|
64
64
|
isEqual,
|
|
65
65
|
);
|
|
66
66
|
|
|
@@ -25,7 +25,7 @@ interface ModelOption {
|
|
|
25
25
|
|
|
26
26
|
const ModelSelect = memo(() => {
|
|
27
27
|
const [model, updateConfig] = useStore((s) => [s.config.model, s.setAgentConfig]);
|
|
28
|
-
const enabledList = useGlobalStore(modelConfigSelectors.
|
|
28
|
+
const enabledList = useGlobalStore(modelConfigSelectors.providerListForModelSelect, isEqual);
|
|
29
29
|
const { styles } = useStyles();
|
|
30
30
|
|
|
31
31
|
const options = useMemo<SelectProps['options']>(() => {
|
|
@@ -24,8 +24,8 @@ const ProviderApiKeyForm = memo<ProviderApiKeyFormProps>(
|
|
|
24
24
|
const [showProxy, setShow] = useState(false);
|
|
25
25
|
|
|
26
26
|
const [apiKey, proxyUrl, setConfig] = useGlobalStore((s) => [
|
|
27
|
-
modelConfigSelectors.
|
|
28
|
-
modelConfigSelectors.
|
|
27
|
+
modelConfigSelectors.getConfigByProviderId(provider)(s)?.apiKey,
|
|
28
|
+
modelConfigSelectors.getConfigByProviderId(provider)(s)?.endpoint,
|
|
29
29
|
s.setModelProviderConfig,
|
|
30
30
|
]);
|
|
31
31
|
|
|
@@ -44,7 +44,7 @@ const ModelSwitchPanel = memo<PropsWithChildren>(({ children }) => {
|
|
|
44
44
|
const updateAgentConfig = useSessionStore((s) => s.updateAgentConfig);
|
|
45
45
|
|
|
46
46
|
const router = useRouter();
|
|
47
|
-
const enabledList = useGlobalStore(modelConfigSelectors.
|
|
47
|
+
const enabledList = useGlobalStore(modelConfigSelectors.providerListForModelSelect, isEqual);
|
|
48
48
|
|
|
49
49
|
const items = useMemo(() => {
|
|
50
50
|
const getModelItems = (provider: ModelProviderCard) => {
|
package/src/services/_auth.ts
CHANGED
|
@@ -29,13 +29,15 @@ export const getProviderAuthPayload = (provider: string) => {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
case ModelProvider.Ollama: {
|
|
32
|
-
const
|
|
32
|
+
const config = modelConfigSelectors.ollamaConfig(useGlobalStore.getState());
|
|
33
33
|
|
|
34
|
-
return { endpoint };
|
|
34
|
+
return { endpoint: config?.endpoint };
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
default: {
|
|
38
|
-
const config = modelConfigSelectors.
|
|
38
|
+
const config = modelConfigSelectors.getConfigByProviderId(provider)(
|
|
39
|
+
useGlobalStore.getState(),
|
|
40
|
+
);
|
|
39
41
|
|
|
40
42
|
return { apiKey: config?.apiKey, endpoint: config?.endpoint };
|
|
41
43
|
}
|
package/src/services/_header.ts
CHANGED
|
@@ -8,14 +8,13 @@ import { modelConfigSelectors, settingsSelectors } from '@/store/global/selector
|
|
|
8
8
|
*/
|
|
9
9
|
// eslint-disable-next-line no-undef
|
|
10
10
|
export const createHeaderWithOpenAI = (header?: HeadersInit): HeadersInit => {
|
|
11
|
-
const
|
|
12
|
-
const endpoint = modelConfigSelectors.openAIProxyUrl(useGlobalStore.getState()) || '';
|
|
11
|
+
const openAIConfig = modelConfigSelectors.openAIConfig(useGlobalStore.getState());
|
|
13
12
|
|
|
14
13
|
// eslint-disable-next-line no-undef
|
|
15
14
|
return {
|
|
16
15
|
...header,
|
|
17
16
|
[LOBE_CHAT_ACCESS_CODE]: settingsSelectors.password(useGlobalStore.getState()),
|
|
18
|
-
[OPENAI_API_KEY_HEADER_KEY]: apiKey,
|
|
19
|
-
[OPENAI_END_POINT]: endpoint,
|
|
17
|
+
[OPENAI_API_KEY_HEADER_KEY]: openAIConfig.apiKey || '',
|
|
18
|
+
[OPENAI_END_POINT]: openAIConfig.endpoint || '',
|
|
20
19
|
};
|
|
21
20
|
};
|
package/src/services/chat.ts
CHANGED
|
@@ -137,7 +137,7 @@ class ChatService {
|
|
|
137
137
|
|
|
138
138
|
// if the provider is Azure, get the deployment name as the request model
|
|
139
139
|
if (provider === ModelProvider.Azure) {
|
|
140
|
-
const chatModelCards = modelConfigSelectors.
|
|
140
|
+
const chatModelCards = modelConfigSelectors.getModelCardsByProviderId(provider)(
|
|
141
141
|
useGlobalStore.getState(),
|
|
142
142
|
);
|
|
143
143
|
|
package/src/services/ollama.ts
CHANGED
|
@@ -11,8 +11,9 @@ const DEFAULT_BASE_URL = 'http://127.0.0.1:11434/v1';
|
|
|
11
11
|
|
|
12
12
|
class OllamaService {
|
|
13
13
|
getHost = (): string => {
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const config = modelConfigSelectors.ollamaConfig(useGlobalStore.getState());
|
|
15
|
+
|
|
16
|
+
const url = new URL(config.endpoint || DEFAULT_BASE_URL);
|
|
16
17
|
return url.host;
|
|
17
18
|
};
|
|
18
19
|
|
|
@@ -46,7 +46,7 @@ describe('LLMSettingsSliceAction', () => {
|
|
|
46
46
|
const payload: CustomModelCardDispatch = { type: 'add', modelCard: { id: 'test-id' } };
|
|
47
47
|
|
|
48
48
|
// Mock the selector to return undefined
|
|
49
|
-
vi.spyOn(modelConfigSelectors, '
|
|
49
|
+
vi.spyOn(modelConfigSelectors, 'getConfigByProviderId').mockReturnValue(() => undefined);
|
|
50
50
|
vi.spyOn(result.current, 'setModelProviderConfig');
|
|
51
51
|
|
|
52
52
|
await act(async () => {
|
|
@@ -37,7 +37,7 @@ export const llmSettingsSlice: StateCreator<
|
|
|
37
37
|
LLMSettingsAction
|
|
38
38
|
> = (set, get) => ({
|
|
39
39
|
dispatchCustomModelCards: async (provider, payload) => {
|
|
40
|
-
const prevState = modelConfigSelectors.
|
|
40
|
+
const prevState = modelConfigSelectors.getConfigByProviderId(provider)(get());
|
|
41
41
|
|
|
42
42
|
if (!prevState) return;
|
|
43
43
|
|
|
@@ -47,7 +47,7 @@ export const llmSettingsSlice: StateCreator<
|
|
|
47
47
|
},
|
|
48
48
|
|
|
49
49
|
removeEnabledModels: async (provider, model) => {
|
|
50
|
-
const config = modelConfigSelectors.
|
|
50
|
+
const config = modelConfigSelectors.getConfigByProviderId(provider)(get());
|
|
51
51
|
|
|
52
52
|
await get().setModelProviderConfig(provider, {
|
|
53
53
|
enabledModels: config?.enabledModels?.filter((s) => s !== model).filter(Boolean),
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { DEFAULT_SETTINGS } from '@/const/settings';
|
|
4
|
-
import { modelProviderSelectors } from '@/store/global/slices/settings/selectors/modelProvider';
|
|
5
|
-
import { agentSelectors } from '@/store/session/slices/agent';
|
|
6
3
|
import { merge } from '@/utils/merge';
|
|
7
4
|
|
|
8
5
|
import { GlobalStore, useGlobalStore } from '../../../store';
|
|
@@ -10,7 +7,7 @@ import { GlobalSettingsState, initialSettingsState } from '../initialState';
|
|
|
10
7
|
import { modelConfigSelectors } from './modelConfig';
|
|
11
8
|
|
|
12
9
|
describe('modelConfigSelectors', () => {
|
|
13
|
-
describe('
|
|
10
|
+
describe('providerListWithConfig', () => {
|
|
14
11
|
it('visible', () => {
|
|
15
12
|
const s = merge(initialSettingsState, {
|
|
16
13
|
settings: {
|
|
@@ -22,7 +19,9 @@ describe('modelConfigSelectors', () => {
|
|
|
22
19
|
},
|
|
23
20
|
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
24
21
|
|
|
25
|
-
const ollamaList = modelConfigSelectors
|
|
22
|
+
const ollamaList = modelConfigSelectors
|
|
23
|
+
.providerListWithConfig(s)
|
|
24
|
+
.find((r) => r.id === 'ollama');
|
|
26
25
|
|
|
27
26
|
expect(ollamaList?.chatModels.find((c) => c.id === 'llava')).toEqual({
|
|
28
27
|
displayName: 'LLaVA 7B',
|
|
@@ -33,9 +32,31 @@ describe('modelConfigSelectors', () => {
|
|
|
33
32
|
vision: true,
|
|
34
33
|
});
|
|
35
34
|
});
|
|
35
|
+
it('with user custom models', () => {
|
|
36
|
+
const s = merge(initialSettingsState, {
|
|
37
|
+
settings: {
|
|
38
|
+
languageModel: {
|
|
39
|
+
perplexity: {
|
|
40
|
+
customModelCards: [{ id: 'sonar-online', displayName: 'Sonar Online' }],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
45
|
+
|
|
46
|
+
const providerList = modelConfigSelectors
|
|
47
|
+
.providerListWithConfig(s)
|
|
48
|
+
.find((r) => r.id === 'perplexity');
|
|
49
|
+
|
|
50
|
+
expect(providerList?.chatModels.find((c) => c.id === 'sonar-online')).toEqual({
|
|
51
|
+
id: 'sonar-online',
|
|
52
|
+
displayName: 'Sonar Online',
|
|
53
|
+
enabled: false,
|
|
54
|
+
isCustom: true,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
36
57
|
});
|
|
37
58
|
|
|
38
|
-
describe('
|
|
59
|
+
describe('isProviderEnabled', () => {
|
|
39
60
|
it('should return true if provider is enabled', () => {
|
|
40
61
|
const s = merge(initialSettingsState, {
|
|
41
62
|
settings: {
|
|
@@ -45,7 +66,7 @@ describe('modelConfigSelectors', () => {
|
|
|
45
66
|
},
|
|
46
67
|
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
47
68
|
|
|
48
|
-
expect(modelConfigSelectors.
|
|
69
|
+
expect(modelConfigSelectors.isProviderEnabled('ollama')(s)).toBe(true);
|
|
49
70
|
});
|
|
50
71
|
|
|
51
72
|
it('should return false if provider is not enabled', () => {
|
|
@@ -57,11 +78,11 @@ describe('modelConfigSelectors', () => {
|
|
|
57
78
|
},
|
|
58
79
|
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
59
80
|
|
|
60
|
-
expect(modelConfigSelectors.
|
|
81
|
+
expect(modelConfigSelectors.isProviderEnabled('perplexity')(s)).toBe(false);
|
|
61
82
|
});
|
|
62
83
|
});
|
|
63
84
|
|
|
64
|
-
describe('
|
|
85
|
+
describe('getModelCardsByProviderId', () => {
|
|
65
86
|
it('should return model cards including custom model cards', () => {
|
|
66
87
|
const s = merge(initialSettingsState, {
|
|
67
88
|
settings: {
|
|
@@ -73,7 +94,7 @@ describe('modelConfigSelectors', () => {
|
|
|
73
94
|
},
|
|
74
95
|
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
75
96
|
|
|
76
|
-
const modelCards = modelConfigSelectors.
|
|
97
|
+
const modelCards = modelConfigSelectors.getModelCardsByProviderId('perplexity')(s);
|
|
77
98
|
|
|
78
99
|
expect(modelCards).toContainEqual({
|
|
79
100
|
id: 'custom-model',
|
|
@@ -83,7 +104,7 @@ describe('modelConfigSelectors', () => {
|
|
|
83
104
|
});
|
|
84
105
|
});
|
|
85
106
|
|
|
86
|
-
describe('
|
|
107
|
+
describe('providerListForModelSelect', () => {
|
|
87
108
|
it('should return only enabled providers', () => {
|
|
88
109
|
const s = merge(initialSettingsState, {
|
|
89
110
|
settings: {
|
|
@@ -94,7 +115,7 @@ describe('modelConfigSelectors', () => {
|
|
|
94
115
|
},
|
|
95
116
|
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
96
117
|
|
|
97
|
-
const enabledProviders = modelConfigSelectors.
|
|
118
|
+
const enabledProviders = modelConfigSelectors.providerListForModelSelect(s);
|
|
98
119
|
expect(enabledProviders).toHaveLength(2);
|
|
99
120
|
expect(enabledProviders[1].id).toBe('perplexity');
|
|
100
121
|
});
|
|
@@ -115,7 +136,7 @@ describe('modelConfigSelectors', () => {
|
|
|
115
136
|
},
|
|
116
137
|
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
117
138
|
|
|
118
|
-
const customModelCard = modelConfigSelectors.
|
|
139
|
+
const customModelCard = modelConfigSelectors.getCustomModelCard({
|
|
119
140
|
id: 'custom-model-2',
|
|
120
141
|
provider: 'perplexity',
|
|
121
142
|
})(s);
|
|
@@ -134,7 +155,7 @@ describe('modelConfigSelectors', () => {
|
|
|
134
155
|
},
|
|
135
156
|
} as GlobalSettingsState) as unknown as GlobalStore;
|
|
136
157
|
|
|
137
|
-
const customModelCard = modelConfigSelectors.
|
|
158
|
+
const customModelCard = modelConfigSelectors.getCustomModelCard({
|
|
138
159
|
id: 'nonexistent-model',
|
|
139
160
|
provider: 'perplexity',
|
|
140
161
|
})(s);
|
|
@@ -7,60 +7,51 @@ import { GlobalStore } from '../../../store';
|
|
|
7
7
|
import { modelProviderSelectors } from './modelProvider';
|
|
8
8
|
import { currentSettings } from './settings';
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const providerConfig = (provider: string) => (s: GlobalStore) =>
|
|
10
|
+
const getConfigByProviderId = (provider: string) => (s: GlobalStore) =>
|
|
13
11
|
currentSettings(s).languageModel[provider as GlobalLLMProviderKey] as
|
|
14
12
|
| GeneralModelProviderConfig
|
|
15
13
|
| undefined;
|
|
16
14
|
|
|
17
|
-
const
|
|
15
|
+
const getModeProviderById = (provider: string) => (s: GlobalStore) =>
|
|
16
|
+
modelProviderSelectors.providerModelList(s).find((s) => s.id === provider);
|
|
17
|
+
|
|
18
|
+
const isProviderEnabled = (provider: GlobalLLMProviderKey) => (s: GlobalStore) =>
|
|
18
19
|
currentSettings(s).languageModel[provider]?.enabled || false;
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
21
|
+
const getEnableModelsByProviderId = (provider: string) => (s: GlobalStore) => {
|
|
22
|
+
if (!getConfigByProviderId(provider)(s)?.enabledModels) return;
|
|
22
23
|
|
|
23
|
-
return
|
|
24
|
+
return getConfigByProviderId(provider)(s)?.enabledModels?.filter(Boolean);
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const zhipuAPIKey = (s: GlobalStore) => modelProvider(s).zhipu.apiKey;
|
|
32
|
-
|
|
33
|
-
const bedrockConfig = (s: GlobalStore) => modelProvider(s).bedrock;
|
|
34
|
-
|
|
35
|
-
const googleAPIKey = (s: GlobalStore) => modelProvider(s).google.apiKey;
|
|
36
|
-
|
|
37
|
-
const enableAzure = (s: GlobalStore) => modelProvider(s).azure.enabled;
|
|
38
|
-
const azureConfig = (s: GlobalStore) => modelProvider(s).azure;
|
|
39
|
-
|
|
40
|
-
const mistralAPIKey = (s: GlobalStore) => modelProvider(s).mistral.apiKey;
|
|
41
|
-
|
|
42
|
-
const moonshotAPIKey = (s: GlobalStore) => modelProvider(s).moonshot.apiKey;
|
|
43
|
-
|
|
44
|
-
const ollamaProxyUrl = (s: GlobalStore) => modelProvider(s).ollama.endpoint;
|
|
45
|
-
|
|
46
|
-
const perplexityAPIKey = (s: GlobalStore) => modelProvider(s).perplexity.apiKey;
|
|
27
|
+
const getModelCardsByProviderId =
|
|
28
|
+
(provider: string) =>
|
|
29
|
+
(s: GlobalStore): ChatModelCard[] => {
|
|
30
|
+
const builtinCards = getModeProviderById(provider)(s)?.chatModels || [];
|
|
47
31
|
|
|
48
|
-
const
|
|
49
|
-
|
|
32
|
+
const userCards = (getConfigByProviderId(provider)(s)?.customModelCards || []).map((model) => ({
|
|
33
|
+
...model,
|
|
34
|
+
isCustom: true,
|
|
35
|
+
}));
|
|
50
36
|
|
|
51
|
-
|
|
37
|
+
return uniqBy([...userCards, ...builtinCards], 'id');
|
|
38
|
+
};
|
|
52
39
|
|
|
53
|
-
const
|
|
40
|
+
const getCustomModelCard =
|
|
41
|
+
({ id, provider }: { id?: string; provider?: string }) =>
|
|
42
|
+
(s: GlobalStore) => {
|
|
43
|
+
if (!provider) return;
|
|
54
44
|
|
|
55
|
-
const
|
|
45
|
+
const config = getConfigByProviderId(provider)(s);
|
|
56
46
|
|
|
57
|
-
|
|
47
|
+
return config?.customModelCards?.find((m) => m.id === id);
|
|
48
|
+
};
|
|
58
49
|
|
|
59
|
-
const
|
|
60
|
-
|
|
50
|
+
const providerListWithConfig = (s: GlobalStore): ModelProviderCard[] =>
|
|
51
|
+
modelProviderSelectors.providerModelList(s).map((list) => ({
|
|
61
52
|
...list,
|
|
62
|
-
chatModels: list.
|
|
63
|
-
const models =
|
|
53
|
+
chatModels: getModelCardsByProviderId(list.id)(s)?.map((model) => {
|
|
54
|
+
const models = getEnableModelsByProviderId(list.id)(s);
|
|
64
55
|
|
|
65
56
|
if (!models) return model;
|
|
66
57
|
|
|
@@ -69,111 +60,57 @@ const modelSelectList = (s: GlobalStore): ModelProviderCard[] => {
|
|
|
69
60
|
enabled: models?.some((m) => m === model.id),
|
|
70
61
|
};
|
|
71
62
|
}),
|
|
72
|
-
enabled:
|
|
63
|
+
enabled: isProviderEnabled(list.id as any)(s),
|
|
73
64
|
}));
|
|
74
|
-
};
|
|
75
65
|
|
|
76
|
-
const
|
|
77
|
-
|
|
66
|
+
const providerListForModelSelect = (s: GlobalStore): ModelProviderCard[] =>
|
|
67
|
+
providerListWithConfig(s)
|
|
78
68
|
.filter((s) => s.enabled)
|
|
79
69
|
.map((provider) => ({
|
|
80
70
|
...provider,
|
|
81
71
|
chatModels: provider.chatModels.filter((model) => model.enabled),
|
|
82
72
|
}));
|
|
83
73
|
|
|
84
|
-
const providerCard = (provider: string) => (s: GlobalStore) =>
|
|
85
|
-
modelProviderSelectors.providerModelList(s).find((s) => s.id === provider);
|
|
86
|
-
|
|
87
|
-
const providerModelCards =
|
|
88
|
-
(provider: string) =>
|
|
89
|
-
(s: GlobalStore): ChatModelCard[] => {
|
|
90
|
-
const builtinCards = providerCard(provider)(s)?.chatModels || [];
|
|
91
|
-
|
|
92
|
-
const userCards = (providerConfig(provider)(s)?.customModelCards || []).map((model) => ({
|
|
93
|
-
...model,
|
|
94
|
-
isCustom: true,
|
|
95
|
-
}));
|
|
96
|
-
|
|
97
|
-
return uniqBy([...userCards, ...builtinCards], 'id');
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const getCustomModelCardById =
|
|
101
|
-
({ id, provider }: { id?: string; provider?: string }) =>
|
|
102
|
-
(s: GlobalStore) => {
|
|
103
|
-
if (!provider) return;
|
|
104
|
-
|
|
105
|
-
const config = providerConfig(provider)(s);
|
|
106
|
-
|
|
107
|
-
return config?.customModelCards?.find((m) => m.id === id);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
74
|
const currentEditingCustomModelCard = (s: GlobalStore) => {
|
|
111
75
|
if (!s.editingCustomCardModel) return;
|
|
112
76
|
const { id, provider } = s.editingCustomCardModel;
|
|
113
77
|
|
|
114
|
-
return
|
|
78
|
+
return getCustomModelCard({ id, provider })(s);
|
|
115
79
|
};
|
|
116
80
|
|
|
117
|
-
const
|
|
81
|
+
const isAutoFetchModelsEnabled =
|
|
118
82
|
(provider: GlobalLLMProviderKey) =>
|
|
119
83
|
(s: GlobalStore): boolean => {
|
|
120
|
-
return
|
|
84
|
+
return getConfigByProviderId(provider)(s)?.autoFetchModelLists || false;
|
|
121
85
|
};
|
|
122
86
|
|
|
87
|
+
const llmSettings = (s: GlobalStore) => currentSettings(s).languageModel;
|
|
88
|
+
|
|
89
|
+
const openAIConfig = (s: GlobalStore) => llmSettings(s).openai;
|
|
90
|
+
const bedrockConfig = (s: GlobalStore) => llmSettings(s).bedrock;
|
|
91
|
+
const ollamaConfig = (s: GlobalStore) => llmSettings(s).ollama;
|
|
92
|
+
const azureConfig = (s: GlobalStore) => llmSettings(s).azure;
|
|
93
|
+
|
|
94
|
+
const isAzureEnabled = (s: GlobalStore) => llmSettings(s).azure.enabled;
|
|
95
|
+
|
|
123
96
|
/* eslint-disable sort-keys-fix/sort-keys-fix, */
|
|
124
97
|
export const modelConfigSelectors = {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
providerConfig,
|
|
128
|
-
providerModelCards,
|
|
98
|
+
isAutoFetchModelsEnabled,
|
|
99
|
+
isProviderEnabled,
|
|
129
100
|
currentEditingCustomModelCard,
|
|
130
|
-
getCustomModelCardById,
|
|
131
101
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
102
|
+
getConfigByProviderId,
|
|
103
|
+
getEnableModelsByProviderId,
|
|
104
|
+
getModelCardsByProviderId,
|
|
105
|
+
getCustomModelCard,
|
|
135
106
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
openAIAPIKey,
|
|
139
|
-
openAIProxyUrl,
|
|
107
|
+
providerListWithConfig,
|
|
108
|
+
providerListForModelSelect,
|
|
140
109
|
|
|
141
|
-
|
|
142
|
-
enableAzure,
|
|
110
|
+
openAIConfig,
|
|
143
111
|
azureConfig,
|
|
144
|
-
// Zhipu
|
|
145
|
-
zhipuAPIKey,
|
|
146
|
-
// Google
|
|
147
|
-
googleAPIKey,
|
|
148
|
-
|
|
149
|
-
// Bedrock
|
|
150
112
|
bedrockConfig,
|
|
113
|
+
ollamaConfig,
|
|
151
114
|
|
|
152
|
-
|
|
153
|
-
moonshotAPIKey,
|
|
154
|
-
|
|
155
|
-
// Ollama
|
|
156
|
-
ollamaProxyUrl,
|
|
157
|
-
|
|
158
|
-
// Perplexity
|
|
159
|
-
perplexityAPIKey,
|
|
160
|
-
|
|
161
|
-
// Anthropic
|
|
162
|
-
anthropicAPIKey,
|
|
163
|
-
anthropicProxyUrl,
|
|
164
|
-
|
|
165
|
-
// Mistral
|
|
166
|
-
mistralAPIKey,
|
|
167
|
-
|
|
168
|
-
// Groq
|
|
169
|
-
groqAPIKey,
|
|
170
|
-
|
|
171
|
-
// OpenRouter
|
|
172
|
-
openrouterAPIKey,
|
|
173
|
-
|
|
174
|
-
// ZeroOne ιΆδΈδΈη©
|
|
175
|
-
zerooneAPIKey,
|
|
176
|
-
|
|
177
|
-
// TogetherAI
|
|
178
|
-
togetheraiAPIKey,
|
|
115
|
+
isAzureEnabled,
|
|
179
116
|
};
|