|
@@ -5,6 +5,7 @@ import {
|
|
|
SILICONFLOW_BASE_URL,
|
|
SILICONFLOW_BASE_URL,
|
|
|
SiliconFlow,
|
|
SiliconFlow,
|
|
|
REQUEST_TIMEOUT_MS_FOR_THINKING,
|
|
REQUEST_TIMEOUT_MS_FOR_THINKING,
|
|
|
|
|
+ DEFAULT_MODELS,
|
|
|
} from "@/app/constant";
|
|
} from "@/app/constant";
|
|
|
import {
|
|
import {
|
|
|
useAccessStore,
|
|
useAccessStore,
|
|
@@ -27,10 +28,19 @@ import {
|
|
|
getMessageTextContentWithoutThinking,
|
|
getMessageTextContentWithoutThinking,
|
|
|
} from "@/app/utils";
|
|
} from "@/app/utils";
|
|
|
import { RequestPayload } from "./openai";
|
|
import { RequestPayload } from "./openai";
|
|
|
|
|
+
|
|
|
import { fetch } from "@/app/utils/stream";
|
|
import { fetch } from "@/app/utils/stream";
|
|
|
|
|
+export interface SiliconFlowListModelResponse {
|
|
|
|
|
+ object: string;
|
|
|
|
|
+ data: Array<{
|
|
|
|
|
+ id: string;
|
|
|
|
|
+ object: string;
|
|
|
|
|
+ root: string;
|
|
|
|
|
+ }>;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
export class SiliconflowApi implements LLMApi {
|
|
export class SiliconflowApi implements LLMApi {
|
|
|
- private disableListModels = true;
|
|
|
|
|
|
|
+ private disableListModels = false;
|
|
|
|
|
|
|
|
path(path: string): string {
|
|
path(path: string): string {
|
|
|
const accessStore = useAccessStore.getState();
|
|
const accessStore = useAccessStore.getState();
|
|
@@ -238,6 +248,36 @@ export class SiliconflowApi implements LLMApi {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async models(): Promise<LLMModel[]> {
|
|
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,
|
|
|
|
|
+ },
|
|
|
|
|
+ }));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|