[feat] better openrouter support

This commit is contained in:
kwaroran
2024-01-04 02:32:53 +09:00
parent 1d5d69b71b
commit 32e3060b19
5 changed files with 41 additions and 6 deletions

View File

@@ -13,10 +13,36 @@ export async function openRouterModels() {
headers: headers
})
const res = await (await aim).json()
return res.data.map((v:any) => {
return v.id
return res.data.map((model: any) => {
let name = model.name
let price = model.pricing.prompt
if(price > 0){
name += ` - $${(price*1000).toFixed(5)}/1k`
}
else{
name += " - Free"
}
return {
id: model.id,
name: name,
price: price,
context_length: model.context_length,
}
}).sort((a: any, b: any) => {
return a.price - b.price
}).filter((model: any) => {
return model.price >= 0
})
} catch (error) {
return []
}
}
export async function getFreeOpenRouterModel(){
const models = await openRouterModels()
return models.filter((model: any) => {
return model.name.endsWith("Free")
}).sort((a: any, b: any) => {
return b.context_length - a.context_length
})[0].id ?? ''
}