Skip to content

Commit 2d1e465

Browse files
authored
Merge pull request #315 from yz778/gemini-models
fix: alternate handler for retrieving Gemini models
2 parents 00024ac + 6145883 commit 2d1e465

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libs/openai.ts

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ export const getAllOpenAIModels = async (baseUrl: string, apiKey?: string) => {
2424

2525
clearTimeout(timeoutId)
2626

27+
// if Google API fails to return models, try another approach
28+
if (res.status === 401 && res.url == 'https://generativelanguage.googleapis.com/v1beta/openai/models') {
29+
const urlGoogle = `https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`
30+
const resGoogle = await fetch(urlGoogle, {
31+
signal: controller.signal
32+
})
33+
34+
const data = await resGoogle.json()
35+
return data.models.map(model => ({
36+
id: model.name.replace(/^models\//, ""),
37+
name: model.name.replace(/^models\//, ""),
38+
})) as Model[]
39+
}
40+
2741
if (!res.ok) {
2842
return []
2943
}

0 commit comments

Comments
 (0)