Uh oh!
There was an error while loading. Please reload this page.
forked from Gerome-Elassaad/CodingIT
- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmodels.ts
More file actions
Latest commit
114 lines (104 loc) · 3.64 KB
/
Copy pathmodels.ts
File metadata and controls
114 lines (104 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import{createAnthropic}from'@ai-sdk/anthropic'
import{createFireworks}from'@ai-sdk/fireworks'
import{createGoogleGenerativeAI}from'@ai-sdk/google'
import{createVertex}from'@ai-sdk/google-vertex'
import{createMistral}from'@ai-sdk/mistral'
import{createOpenAI}from'@ai-sdk/openai'
import{createOllama}from'ollama-ai-provider'
import{createOpenRouter}from'@openrouter/ai-sdk-provider'
exporttypeLLMModel={
id: string
name: string
provider: string
providerId: string
isBeta?: boolean
}
exporttypeLLMModelConfig={
model?: string
apiKey?: string
baseURL?: string
temperature?: number
topP?: number
topK?: number
frequencyPenalty?: number
presencePenalty?: number
maxTokens?: number
}
exportfunctiongetModelClient(model: LLMModel,config: LLMModelConfig){
const{id: modelNameString, providerId }=model
const{ apiKey, baseURL }=config
constproviderConfigs={
anthropic: ()=>createAnthropic({ apiKey, baseURL })(modelNameString),
openai: ()=>createOpenAI({ apiKey, baseURL })(modelNameString),
google: ()=>
createGoogleGenerativeAI({ apiKey, baseURL })(modelNameString),
mistral: ()=>createMistral({ apiKey, baseURL })(modelNameString),
groq: ()=>
createOpenAI({
apiKey: apiKey||process.env.GROQ_API_KEY,
baseURL: baseURL||'https://api.groq.com/openai/v1',
})(modelNameString),
togetherai: ()=>
createOpenAI({
apiKey: apiKey||process.env.TOGETHER_API_KEY,
baseURL: baseURL||'https://api.together.xyz/v1',
})(modelNameString),
ollama: ()=>createOllama({ baseURL })(modelNameString),
fireworks: ()=>
createFireworks({
apiKey: apiKey||process.env.FIREWORKS_API_KEY,
baseURL: baseURL||'https://api.fireworks.ai/inference/v1',
})(modelNameString),
vertex: ()=>{
constvertexCredentials=process.env.GOOGLE_VERTEX_CREDENTIALS;
// Handle both API key and JSON credentials
if(!vertexCredentials){
// Fallback to Google AI SDK if no Vertex credentials
returncreateGoogleGenerativeAI({
apiKey: apiKey||process.env.GOOGLE_AI_API_KEY
})(modelNameString);
}
// Try to parse as JSON first (service account credentials)
try{
constcredentials=JSON.parse(vertexCredentials);
returncreateVertex({
googleAuthOptions: { credentials },
})(modelNameString);
}catch{
// If not JSON, treat as API key and use Google AI SDK instead
returncreateGoogleGenerativeAI({
apiKey: vertexCredentials||apiKey||process.env.GOOGLE_AI_API_KEY
})(modelNameString);
}
},
xai: ()=>
createOpenAI({
apiKey: apiKey||process.env.XAI_API_KEY,
baseURL: baseURL||'https://api.x.ai/v1',
})(modelNameString),
deepseek: ()=>
createOpenAI({
apiKey: apiKey||process.env.DEEPSEEK_API_KEY,
baseURL: baseURL||'https://api.deepseek.com/v1',
})(modelNameString),
openrouter: ()=>
createOpenRouter({
apiKey: apiKey||process.env.OPENROUTER_API_KEY,
baseURL: baseURL||'https://openrouter.ai/api/v1',
})(modelNameString),
}
constcreateClient=
providerConfigs[providerIdaskeyoftypeofproviderConfigs]
if(!createClient){
thrownewError(`Unsupported provider: ${providerId}`)
}
returncreateClient()
}
exportfunctiongetDefaultModelParams(model: LLMModel){
// Return default parameters for the model
// This can be customized per provider/model if needed
return{
temperature: 0.7,
maxTokens: 4096,
}
}