1
+ import { LOBE_DEFAULT_MODEL_LIST } from '@/config/modelProviders' ;
2
+
1
3
import { AgentRuntimeErrorType } from '../error' ;
2
4
import { ModelProvider } from '../types' ;
3
5
import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory' ;
6
+ import { OpenRouterModelCard } from './type' ;
4
7
5
8
export const LobeOpenRouterAI = LobeOpenAICompatibleFactory ( {
6
9
baseURL : 'https://openrouter.ai/api/v1' ,
@@ -13,9 +16,29 @@ export const LobeOpenRouterAI = LobeOpenAICompatibleFactory({
13
16
debug : {
14
17
chatCompletion : ( ) => process . env . DEBUG_OPENROUTER_CHAT_COMPLETION === '1' ,
15
18
} ,
19
+
16
20
errorType : {
17
21
bizError : AgentRuntimeErrorType . OpenRouterBizError ,
18
22
invalidAPIKey : AgentRuntimeErrorType . InvalidOpenRouterAPIKey ,
19
23
} ,
24
+ models : {
25
+ transformModel : ( m ) => {
26
+ const model = m as unknown as OpenRouterModelCard ;
27
+
28
+ return {
29
+ description : model . description ,
30
+ displayName : model . name ,
31
+ enabled : LOBE_DEFAULT_MODEL_LIST . find ( ( m ) => model . id . endsWith ( m . id ) ) ?. enabled || false ,
32
+ functionCall : model . description . includes ( 'function calling' ) ,
33
+ id : model . id ,
34
+ maxTokens :
35
+ typeof model . top_provider . max_completion_tokens === 'number'
36
+ ? model . top_provider . max_completion_tokens
37
+ : undefined ,
38
+ tokens : model . context_length ,
39
+ vision : model . description . includes ( 'vision' ) ,
40
+ } ;
41
+ } ,
42
+ } ,
20
43
provider : ModelProvider . OpenRouter ,
21
44
} ) ;
0 commit comments