Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#6193 from siliconflow/get-models-si…
Browse files Browse the repository at this point in the history
…liconflow

Model listing of SiliconFlow
  • Loading branch information
Leizhenpeng authored Feb 11, 2025
2 parents b44686b + 2137aa6 commit 77c78b2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
44 changes: 42 additions & 2 deletions app/client/platforms/siliconflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SILICONFLOW_BASE_URL,
SiliconFlow,
REQUEST_TIMEOUT_MS_FOR_THINKING,
DEFAULT_MODELS,
} from "@/app/constant";
import {
useAccessStore,
Expand All @@ -28,10 +29,19 @@ import {
isVisionModel,
} from "@/app/utils";
import { RequestPayload } from "./openai";

import { fetch } from "@/app/utils/stream";
export interface SiliconFlowListModelResponse {
object: string;
data: Array<{
id: string;
object: string;
root: string;
}>;
}

export class SiliconflowApi implements LLMApi {
private disableListModels = true;
private disableListModels = false;

path(path: string): string {
const accessStore = useAccessStore.getState();
Expand Down Expand Up @@ -242,6 +252,36 @@ export class SiliconflowApi implements LLMApi {
}

async models(): Promise<LLMModel[]> {
return [];
if (this.disableListModels) {
return DEFAULT_MODELS.slice();
}

const res = await fetch(this.path(SiliconFlow.ListModelPath), {
method: "GET",
headers: {
...getHeaders(),
},
});

const resJson = (await res.json()) as SiliconFlowListModelResponse;
const chatModels = resJson.data;
console.log("[Models]", chatModels);

if (!chatModels) {
return [];
}

let seq = 1000; //同 Constant.ts 中的排序保持一致
return chatModels.map((m) => ({
name: m.id,
available: true,
sorted: seq++,
provider: {
id: "siliconflow",
providerName: "SiliconFlow",
providerType: "siliconflow",
sorted: 14,
},
}));
}
}
1 change: 1 addition & 0 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export const ChatGLM = {
export const SiliconFlow = {
ExampleEndpoint: SILICONFLOW_BASE_URL,
ChatPath: "v1/chat/completions",
ListModelPath: "v1/models?&sub_type=chat",
};

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

0 comments on commit 77c78b2

Please sign in to comment.