File tree 3 files changed +28
-19
lines changed
store/global/slices/settings/actions
3 files changed +28
-19
lines changed Original file line number Diff line number Diff line change 1
1
import { dataSync } from '@/database/core' ;
2
- import { createHeaderWithAuth } from '@/services/_auth' ;
3
- import { ChatModelCard } from '@/types/llm' ;
4
2
import { GlobalServerConfig } from '@/types/serverConfig' ;
5
3
import { StartDataSyncParams } from '@/types/sync' ;
6
4
@@ -37,21 +35,6 @@ class GlobalService {
37
35
38
36
return false ;
39
37
} ;
40
-
41
- getChatModels = async ( provider : string ) : Promise < ChatModelCard [ ] | undefined > => {
42
- const headers = await createHeaderWithAuth ( {
43
- headers : { 'Content-Type' : 'application/json' } ,
44
- provider,
45
- } ) ;
46
-
47
- try {
48
- const res = await fetch ( API_ENDPOINTS . chatModels ( provider ) , { headers } ) ;
49
-
50
- return res . json ( ) ;
51
- } catch {
52
- return ;
53
- }
54
- } ;
55
38
}
56
39
57
40
export const globalService = new GlobalService ( ) ;
Original file line number Diff line number Diff line change
1
+ import { createHeaderWithAuth } from '@/services/_auth' ;
2
+ import { ChatModelCard } from '@/types/llm' ;
3
+
4
+ import { API_ENDPOINTS } from './_url' ;
5
+
6
+ class ModelsService {
7
+ getChatModels = async ( provider : string ) : Promise < ChatModelCard [ ] | undefined > => {
8
+ const headers = await createHeaderWithAuth ( {
9
+ headers : { 'Content-Type' : 'application/json' } ,
10
+ provider,
11
+ } ) ;
12
+
13
+ try {
14
+ const res = await fetch ( API_ENDPOINTS . chatModels ( provider ) , { headers } ) ;
15
+
16
+ return res . json ( ) ;
17
+ } catch {
18
+ return ;
19
+ }
20
+ } ;
21
+ }
22
+
23
+ export const modelsService = new ModelsService ( ) ;
Original file line number Diff line number Diff line change 1
1
import useSWR , { SWRResponse } from 'swr' ;
2
2
import type { StateCreator } from 'zustand/vanilla' ;
3
3
4
- import { globalService } from '@/services/global' ;
5
4
import { GlobalStore } from '@/store/global' ;
6
5
import { ChatModelCard } from '@/types/llm' ;
7
6
import { GlobalLLMConfig , GlobalLLMProviderKey } from '@/types/settings' ;
@@ -68,7 +67,11 @@ export const llmSettingsSlice: StateCreator<
68
67
useFetchProviderModelList : ( provider , enabledAutoFetch ) =>
69
68
useSWR < ChatModelCard [ ] | undefined > (
70
69
[ provider , enabledAutoFetch ] ,
71
- ( [ p ] ) => globalService . getChatModels ( p ) ,
70
+ async ( [ p ] ) => {
71
+ const { modelsService } = await import ( '@/services/models' ) ;
72
+
73
+ return modelsService . getChatModels ( p ) ;
74
+ } ,
72
75
{
73
76
onSuccess : async ( data ) => {
74
77
if ( data ) {
You can’t perform that action at this time.
0 commit comments