|
@@ -1,6 +1,7 @@
|
|
|
-import { ProviderID, type ModelID } from "../schema"
|
|
|
|
|
|
|
+import { HttpOptions, ProviderID, mergeHttpOptions, type ModelID } from "../schema"
|
|
|
import * as OpenAICompatibleChat from "../protocols/openai-compatible-chat"
|
|
import * as OpenAICompatibleChat from "../protocols/openai-compatible-chat"
|
|
|
import type { RouteDefaultsInput } from "../route/client"
|
|
import type { RouteDefaultsInput } from "../route/client"
|
|
|
|
|
+import { Auth } from "../route/auth"
|
|
|
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options"
|
|
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options"
|
|
|
import type { ProviderPackage } from "../provider-package"
|
|
import type { ProviderPackage } from "../provider-package"
|
|
|
import { profiles, type OpenAICompatibleProfile } from "./openai-compatible-profile"
|
|
import { profiles, type OpenAICompatibleProfile } from "./openai-compatible-profile"
|
|
@@ -19,6 +20,8 @@ export interface Settings extends ProviderPackage.Settings {
|
|
|
readonly apiKey?: string
|
|
readonly apiKey?: string
|
|
|
readonly baseURL: string
|
|
readonly baseURL: string
|
|
|
readonly provider?: string
|
|
readonly provider?: string
|
|
|
|
|
+ readonly http?: RouteDefaultsInput["http"]
|
|
|
|
|
+ readonly providerOptions?: OpenAIProviderOptionsInput
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export type FamilyModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
|
|
export type FamilyModelOptions = Omit<RouteDefaultsInput, "providerOptions"> &
|
|
@@ -31,16 +34,24 @@ export const routes = [OpenAICompatibleChat.route]
|
|
|
|
|
|
|
|
export const configure = (input: GenericModelOptions) => {
|
|
export const configure = (input: GenericModelOptions) => {
|
|
|
const provider = input.provider ?? "openai-compatible"
|
|
const provider = input.provider ?? "openai-compatible"
|
|
|
- const { provider: _, baseURL, apiKey: _apiKey, auth: _auth, ...rest } = input
|
|
|
|
|
|
|
+ const {
|
|
|
|
|
+ provider: _,
|
|
|
|
|
+ baseURL,
|
|
|
|
|
+ apiKey: _apiKey,
|
|
|
|
|
+ auth: _auth,
|
|
|
|
|
+ headers,
|
|
|
|
|
+ ...rest
|
|
|
|
|
+ } = input
|
|
|
const route = OpenAICompatibleChat.route.with({
|
|
const route = OpenAICompatibleChat.route.with({
|
|
|
...rest,
|
|
...rest,
|
|
|
provider,
|
|
provider,
|
|
|
endpoint: { baseURL },
|
|
endpoint: { baseURL },
|
|
|
- auth: AuthOptions.bearer(input, []),
|
|
|
|
|
|
|
+ auth: AuthOptions.bearer(input, []).andThen(Auth.headers(headers ?? {})),
|
|
|
})
|
|
})
|
|
|
return {
|
|
return {
|
|
|
id: ProviderID.make(provider),
|
|
id: ProviderID.make(provider),
|
|
|
model: (modelID: string | ModelID) =>
|
|
model: (modelID: string | ModelID) =>
|
|
|
|
|
+ // oxlint-disable-next-line typescript-eslint/no-unnecessary-type-arguments -- preserves provider-option validation at call sites
|
|
|
route.model<OpenAIProviderOptionsInput>({ id: modelID, provider: ProviderID.make(provider) }),
|
|
route.model<OpenAIProviderOptionsInput>({ id: modelID, provider: ProviderID.make(provider) }),
|
|
|
configure,
|
|
configure,
|
|
|
}
|
|
}
|
|
@@ -67,14 +78,18 @@ export const provider = {
|
|
|
configure,
|
|
configure,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"] = (modelID, settings) =>
|
|
|
|
|
|
|
+export const model: ProviderPackage.Definition<Settings>["model"] = (modelID, settings) =>
|
|
|
configure({
|
|
configure({
|
|
|
apiKey: settings.apiKey,
|
|
apiKey: settings.apiKey,
|
|
|
baseURL: settings.baseURL,
|
|
baseURL: settings.baseURL,
|
|
|
headers: settings.headers === undefined ? undefined : { ...settings.headers },
|
|
headers: settings.headers === undefined ? undefined : { ...settings.headers },
|
|
|
- http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
|
|
|
|
|
|
+ http: mergeHttpOptions(
|
|
|
|
|
+ settings.http === undefined ? undefined : HttpOptions.make(settings.http),
|
|
|
|
|
+ settings.body === undefined ? undefined : new HttpOptions({ body: { ...settings.body } }),
|
|
|
|
|
+ ),
|
|
|
limits: settings.limits,
|
|
limits: settings.limits,
|
|
|
provider: settings.provider,
|
|
provider: settings.provider,
|
|
|
|
|
+ providerOptions: settings.providerOptions,
|
|
|
}).model(modelID)
|
|
}).model(modelID)
|
|
|
|
|
|
|
|
export const baseten = define(profiles.baseten)
|
|
export const baseten = define(profiles.baseten)
|