@@ -58,7 +58,7 @@ export const LobeOpenRouterAI = createOpenAICompatibleRuntime({
5858 let modelList : OpenRouterModelCard [ ] = [ ] ;
5959
6060 try {
61- const response = await fetch ( 'https://openrouter.ai/api/frontend /models' ) ;
61+ const response = await fetch ( 'https://openrouter.ai/api/v1 /models' ) ;
6262 if ( response . ok ) {
6363 const data = await response . json ( ) ;
6464 modelList = data [ 'data' ] ;
@@ -70,44 +70,56 @@ export const LobeOpenRouterAI = createOpenAICompatibleRuntime({
7070
7171 // 处理前端获取的模型信息,转换为标准格式
7272 const formattedModels = modelList . map ( ( model ) => {
73- const { endpoint } = model ;
74- const endpointModel = endpoint ?. model ;
73+ const { top_provider, architecture, pricing, supported_parameters } = model ;
7574
76- const inputModalities = endpointModel ? .input_modalities || model . input_modalities ;
75+ const inputModalities = architecture . input_modalities || [ ] ;
7776
78- let displayName = model . slug ?. toLowerCase ( ) . includes ( 'deepseek' ) && ! model . short_name ?. toLowerCase ( ) . includes ( 'deepseek' )
79- ? ( model . name ?? model . slug )
80- : ( model . short_name ?? model . name ?? model . slug ) ;
77+ // 处理 name,默认去除冒号及其前面的内容
78+ let displayName = model . name ;
79+ const colonIndex = displayName . indexOf ( ':' ) ;
80+ if ( colonIndex !== - 1 ) {
81+ const prefix = displayName . substring ( 0 , colonIndex ) . trim ( ) ;
82+ const suffix = displayName . substring ( colonIndex + 1 ) . trim ( ) ;
8183
82- const inputPrice = formatPrice ( endpoint ?. pricing ?. prompt ) ;
83- const outputPrice = formatPrice ( endpoint ?. pricing ?. completion ) ;
84- const cachedInputPrice = formatPrice ( endpoint ?. pricing ?. input_cache_read ) ;
85- const writeCacheInputPrice = formatPrice ( endpoint ?. pricing ?. input_cache_write ) ;
84+ const isDeepSeekPrefix = prefix . toLowerCase ( ) === 'deepseek' ;
85+ const suffixHasDeepSeek = suffix . toLowerCase ( ) . includes ( 'deepseek' ) ;
86+
87+ if ( isDeepSeekPrefix && ! suffixHasDeepSeek ) {
88+ displayName = model . name ;
89+ } else {
90+ displayName = suffix ;
91+ }
92+ }
93+
94+ const inputPrice = formatPrice ( pricing . prompt ) ;
95+ const outputPrice = formatPrice ( pricing . completion ) ;
96+ const cachedInputPrice = formatPrice ( pricing . input_cache_read ) ;
97+ const writeCacheInputPrice = formatPrice ( pricing . input_cache_write ) ;
8698
8799 const isFree = ( inputPrice === 0 || outputPrice === 0 ) && ! displayName . endsWith ( '(free)' ) ;
88100 if ( isFree ) {
89101 displayName += ' (free)' ;
90102 }
91103
92104 return {
93- contextWindowTokens : endpoint ? .context_length || model . context_length ,
94- description : endpointModel ?. description || model . description ,
105+ contextWindowTokens : top_provider . context_length || model . context_length ,
106+ description : model . description ,
95107 displayName,
96- functionCall : endpoint ?. supports_tool_parameters || false ,
97- id : endpoint ?. model_variant_slug || model . slug ,
108+ functionCall : supported_parameters . includes ( 'tools' ) ,
109+ id : model . id ,
98110 maxOutput :
99- typeof endpoint ? .max_completion_tokens === 'number'
100- ? endpoint . max_completion_tokens
111+ typeof top_provider . max_completion_tokens === 'number'
112+ ? top_provider . max_completion_tokens
101113 : undefined ,
102114 pricing : {
103115 input : inputPrice ,
104116 cachedInput : cachedInputPrice ,
105117 writeCacheInput : writeCacheInputPrice ,
106118 output : outputPrice ,
107119 } ,
108- reasoning : endpoint ?. supports_reasoning || false ,
109- releasedAt : new Date ( model . created_at ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
110- vision : Array . isArray ( inputModalities ) && inputModalities . includes ( 'image' ) ,
120+ reasoning : supported_parameters . includes ( 'reasoning' ) ,
121+ releasedAt : new Date ( model . created * 1000 ) . toISOString ( ) . split ( 'T' ) [ 0 ] ,
122+ vision : inputModalities . includes ( 'image' ) ,
111123 } ;
112124 } ) ;
113125
0 commit comments