fix: alternate handler for retrieving Gemini models
This commit is contained in:
parent
b6814a9e19
commit
af89743039
@ -2,6 +2,7 @@ type Model = {
|
|||||||
id: string
|
id: string
|
||||||
name?: string
|
name?: string
|
||||||
display_name?: string
|
display_name?: string
|
||||||
|
displayName?: string
|
||||||
type: string
|
type: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,6 +25,20 @@ export const getAllOpenAIModels = async (baseUrl: string, apiKey?: string) => {
|
|||||||
|
|
||||||
clearTimeout(timeoutId)
|
clearTimeout(timeoutId)
|
||||||
|
|
||||||
|
// if Gemini fails to return models, try another approach
|
||||||
|
if (res.status === 401 && res.url == 'https://generativelanguage.googleapis.com/v1beta/openai/models') {
|
||||||
|
const urlGoogle = `https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`
|
||||||
|
const resGoogle = await fetch(urlGoogle, {
|
||||||
|
signal: controller.signal
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = await resGoogle.json()
|
||||||
|
return data.models.map(model => ({
|
||||||
|
id: model.name.replace(/^models\//, ""),
|
||||||
|
name: model.displayName,
|
||||||
|
})) as Model[]
|
||||||
|
}
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user