Skip to content

Commit 1583011

Browse files
committed
🚨 chore: fix circular
1 parent 571b6dd commit 1583011

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/services/global.ts

-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { dataSync } from '@/database/core';
2-
import { createHeaderWithAuth } from '@/services/_auth';
3-
import { ChatModelCard } from '@/types/llm';
42
import { GlobalServerConfig } from '@/types/serverConfig';
53
import { StartDataSyncParams } from '@/types/sync';
64

@@ -37,21 +35,6 @@ class GlobalService {
3735

3836
return false;
3937
};
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-
};
5538
}
5639

5740
export const globalService = new GlobalService();

src/services/models.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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();

src/store/global/slices/settings/actions/llm.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import useSWR, { SWRResponse } from 'swr';
22
import type { StateCreator } from 'zustand/vanilla';
33

4-
import { globalService } from '@/services/global';
54
import { GlobalStore } from '@/store/global';
65
import { ChatModelCard } from '@/types/llm';
76
import { GlobalLLMConfig, GlobalLLMProviderKey } from '@/types/settings';
@@ -68,7 +67,11 @@ export const llmSettingsSlice: StateCreator<
6867
useFetchProviderModelList: (provider, enabledAutoFetch) =>
6968
useSWR<ChatModelCard[] | undefined>(
7069
[provider, enabledAutoFetch],
71-
([p]) => globalService.getChatModels(p),
70+
async ([p]) => {
71+
const { modelsService } = await import('@/services/models');
72+
73+
return modelsService.getChatModels(p);
74+
},
7275
{
7376
onSuccess: async (data) => {
7477
if (data) {

0 commit comments

Comments
 (0)