Created
March 26, 2025 20:45
-
-
Save flexchar/4e6ae65810606b6ff11a3d58d0c8c691 to your computer and use it in GitHub Desktop.
good old days abstracting providers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mistral } from '@/functions/ai/providers/mistral'; | |
import { | |
ClaudeModels, | |
DeepInfraModels, | |
VertexModels, | |
OpenAiModels, | |
GoogleStudioModels, | |
FireworksModel, | |
MistralModels, | |
} from '@/static/models'; | |
import { env } from 'hono/adapter'; | |
import { vertex } from '@/functions/ai/providers/vertex'; | |
import { openai } from '@/functions/ai/providers/openai'; | |
import { deepinfra } from '@/functions/ai/providers/deepinfra'; | |
import { claude } from '@/functions/ai/providers/claude'; | |
import { google } from '@/functions/ai/providers/google'; | |
import { fireworks } from '@/functions/ai/providers/fireworks'; | |
import type { ProvidedModels } from '@/functions/ai/getModels'; | |
import type { textStreamOptions } from '@/functions/ai/useAi'; | |
export async function initializeAiClientFromModelName( | |
model: ProvidedModels, | |
c: Context, | |
extraHeliconeMeta: Record<string, string>, | |
) { | |
let client: textStreamOptions['model'] | undefined; | |
if (Object.values(VertexModels).includes(model)) { | |
const isGeminiExperimental = | |
model === VertexModels.Gemini_Experimental_Free; | |
const isModelOnlyInUSA = isGeminiExperimental; | |
const region = isModelOnlyInUSA ? 'us-central1' : undefined; | |
client = await vertex(c, model, extraHeliconeMeta, region); | |
} | |
if (Object.values(DeepInfraModels).includes(model)) { | |
client = deepinfra(env(c), model, extraHeliconeMeta); | |
} | |
if (Object.values(OpenAiModels).includes(model)) { | |
client = openai(env(c), model, extraHeliconeMeta); | |
} | |
if (Object.values(ClaudeModels).includes(model)) { | |
client = claude(env(c), model, extraHeliconeMeta); | |
} | |
if (Object.values(GoogleStudioModels).includes(model)) { | |
client = google(env(c), model, extraHeliconeMeta); | |
} | |
if (Object.values(FireworksModel).includes(model)) { | |
client = fireworks(env(c), model, extraHeliconeMeta); | |
} | |
if (Object.values(MistralModels).includes(model)) { | |
client = mistral(env(c), model, extraHeliconeMeta); | |
} | |
return client; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment