feat: Add OpenAI provider support

This commit is contained in:
n4ze3m
2024-10-12 18:28:29 +05:30
parent acce9b97f6
commit f1e40d5908
12 changed files with 227 additions and 27 deletions

View File

@@ -1,25 +1,40 @@
type Model = {
id: string
name?: string
display_name?: string
type: string
}
export const getAllOpenAIModels = async (baseUrl: string, apiKey?: string) => {
const url = `${baseUrl}/models`
const headers = apiKey
? {
try {
const url = `${baseUrl}/models`
const headers = apiKey
? {
Authorization: `Bearer ${apiKey}`
}
: {}
}
: {}
const res = await fetch(url, {
headers
})
const res = await fetch(url, {
headers
})
if (!res.ok) {
if (!res.ok) {
return []
}
if (baseUrl === "https://api.together.xyz/v1") {
const data = (await res.json()) as Model[]
return data.map(model => ({
id: model.id,
name: model.display_name,
}))
}
const data = (await res.json()) as { data: Model[] }
return data.data
} catch (e) {
console.log(e)
return []
}
const data = (await res.json()) as { data: Model[] }
return data.data
}