Skip to content

Commit 77c78b2

Browse files
authored
Merge pull request #6193 from siliconflow/get-models-siliconflow
Model listing of SiliconFlow
2 parents b44686b + 2137aa6 commit 77c78b2

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

app/client/platforms/siliconflow.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
SILICONFLOW_BASE_URL,
66
SiliconFlow,
77
REQUEST_TIMEOUT_MS_FOR_THINKING,
8+
DEFAULT_MODELS,
89
} from "@/app/constant";
910
import {
1011
useAccessStore,
@@ -28,10 +29,19 @@ import {
2829
isVisionModel,
2930
} from "@/app/utils";
3031
import { RequestPayload } from "./openai";
32+
3133
import { fetch } from "@/app/utils/stream";
34+
export interface SiliconFlowListModelResponse {
35+
object: string;
36+
data: Array<{
37+
id: string;
38+
object: string;
39+
root: string;
40+
}>;
41+
}
3242

3343
export class SiliconflowApi implements LLMApi {
34-
private disableListModels = true;
44+
private disableListModels = false;
3545

3646
path(path: string): string {
3747
const accessStore = useAccessStore.getState();
@@ -242,6 +252,36 @@ export class SiliconflowApi implements LLMApi {
242252
}
243253

244254
async models(): Promise<LLMModel[]> {
245-
return [];
255+
if (this.disableListModels) {
256+
return DEFAULT_MODELS.slice();
257+
}
258+
259+
const res = await fetch(this.path(SiliconFlow.ListModelPath), {
260+
method: "GET",
261+
headers: {
262+
...getHeaders(),
263+
},
264+
});
265+
266+
const resJson = (await res.json()) as SiliconFlowListModelResponse;
267+
const chatModels = resJson.data;
268+
console.log("[Models]", chatModels);
269+
270+
if (!chatModels) {
271+
return [];
272+
}
273+
274+
let seq = 1000; //同 Constant.ts 中的排序保持一致
275+
return chatModels.map((m) => ({
276+
name: m.id,
277+
available: true,
278+
sorted: seq++,
279+
provider: {
280+
id: "siliconflow",
281+
providerName: "SiliconFlow",
282+
providerType: "siliconflow",
283+
sorted: 14,
284+
},
285+
}));
246286
}
247287
}

app/constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export const ChatGLM = {
258258
export const SiliconFlow = {
259259
ExampleEndpoint: SILICONFLOW_BASE_URL,
260260
ChatPath: "v1/chat/completions",
261+
ListModelPath: "v1/models?&sub_type=chat",
261262
};
262263

263264
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang

0 commit comments

Comments
 (0)