55 SILICONFLOW_BASE_URL ,
66 SiliconFlow ,
77 REQUEST_TIMEOUT_MS_FOR_THINKING ,
8+ DEFAULT_MODELS ,
89} from "@/app/constant" ;
910import {
1011 useAccessStore ,
@@ -28,10 +29,19 @@ import {
2829 isVisionModel ,
2930} from "@/app/utils" ;
3031import { RequestPayload } from "./openai" ;
32+
3133import { 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
3343export 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}
0 commit comments