|
|
@@ -1,10 +1,9 @@
|
|
|
import { ProviderID, type ModelID } from "../schema"
|
|
|
-import * as OpenAICompatibleChat from "../protocols/openai-compatible-chat"
|
|
|
+import { OpenAICompatibleChat } from "../protocols/openai-compatible-chat"
|
|
|
import type { RouteDefaultsInput } from "../route/client"
|
|
|
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options"
|
|
|
import { Auth } from "../route/auth"
|
|
|
import { ProviderPackage } from "../provider-package"
|
|
|
-import { profiles, type OpenAICompatibleProfile } from "./openai-compatible-profile"
|
|
|
|
|
|
export const id = ProviderID.make("openai-compatible")
|
|
|
|
|
|
@@ -14,11 +13,6 @@ type GenericModelOptions = RouteDefaultsInput &
|
|
|
readonly baseURL: string
|
|
|
}
|
|
|
|
|
|
-export type FamilyModelOptions = RouteDefaultsInput &
|
|
|
- ProviderAuthOption<"optional"> & {
|
|
|
- readonly baseURL?: string
|
|
|
- }
|
|
|
-
|
|
|
export interface OpenAICompatibleSettings extends ProviderPackage.Settings {}
|
|
|
|
|
|
export const routes = [OpenAICompatibleChat.route]
|
|
|
@@ -39,42 +33,15 @@ export const configure = (input: GenericModelOptions) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const define = (profile: OpenAICompatibleProfile) => {
|
|
|
- const configureProfile = (input: FamilyModelOptions = {}) => {
|
|
|
- const facade = configure({
|
|
|
- ...input,
|
|
|
- baseURL: input.baseURL ?? profile.baseURL,
|
|
|
- provider: profile.provider,
|
|
|
- })
|
|
|
- return {
|
|
|
- id: ProviderID.make(profile.provider),
|
|
|
- model: facade.model,
|
|
|
- configure: configureProfile,
|
|
|
- }
|
|
|
- }
|
|
|
- return configureProfile()
|
|
|
-}
|
|
|
-
|
|
|
-export const provider = {
|
|
|
- id,
|
|
|
- configure,
|
|
|
-}
|
|
|
-
|
|
|
export const model = ProviderPackage.define((modelID, settings: OpenAICompatibleSettings) =>
|
|
|
- OpenAICompatibleChat.model(modelID, {
|
|
|
- auth: settings.apiKey === undefined ? Auth.none : Auth.bearer(settings.apiKey),
|
|
|
- baseURL: settings.baseURL,
|
|
|
- headers: settings.headers,
|
|
|
- providerOptions: settings.providerOptions === undefined ? undefined : { openai: settings.providerOptions },
|
|
|
- body: settings.body,
|
|
|
- limits: settings.limits,
|
|
|
- }),
|
|
|
+ OpenAICompatibleChat.route
|
|
|
+ .with({
|
|
|
+ auth: settings.apiKey === undefined ? Auth.none : Auth.bearer(settings.apiKey),
|
|
|
+ endpoint: { baseURL: settings.baseURL },
|
|
|
+ headers: settings.headers,
|
|
|
+ providerOptions: settings.providerOptions && { openai: settings.providerOptions },
|
|
|
+ http: { body: settings.body },
|
|
|
+ limits: settings.limits,
|
|
|
+ })
|
|
|
+ .model({ id: modelID, provider: "openai-compatible" }),
|
|
|
)
|
|
|
-
|
|
|
-export const baseten = define(profiles.baseten)
|
|
|
-export const cerebras = define(profiles.cerebras)
|
|
|
-export const deepinfra = define(profiles.deepinfra)
|
|
|
-export const deepseek = define(profiles.deepseek)
|
|
|
-export const fireworks = define(profiles.fireworks)
|
|
|
-export const groq = define(profiles.groq)
|
|
|
-export const togetherai = define(profiles.togetherai)
|