fix(core): preserve model request semantics (#30990)
This commit is contained in:
parent
ca9bf7abf9
commit
0bdd9aa494
17 changed files with 525 additions and 48 deletions
|
|
@ -6,6 +6,7 @@ import { ConfigMCPV1 } from "./mcp"
|
|||
import { ConfigPermissionV1 } from "./permission"
|
||||
import { ConfigProviderV1 } from "./provider"
|
||||
import { ConfigProviderOptionsV1 } from "./provider-options"
|
||||
import { ModelRequest } from "../../model-request"
|
||||
|
||||
const keys = new Set([
|
||||
"logLevel",
|
||||
|
|
@ -182,6 +183,13 @@ function migrateProvider(info: ConfigProviderV1.Info) {
|
|||
}
|
||||
|
||||
function migrateModel(info: typeof ConfigProviderV1.Model.Type, packageName?: string) {
|
||||
const packageID = info.provider?.npm ?? packageName
|
||||
const lowerer = ConfigProviderOptionsV1.get(packageID)
|
||||
const ingest = (options: Readonly<Record<string, unknown>>) => {
|
||||
const request = ModelRequest.normalizeAiSdkOptions(packageID, options)
|
||||
return { ...lowerer.request(request.body), ...request.generation, ...request.options }
|
||||
}
|
||||
const request = info.options && ingest(info.options)
|
||||
const costs = info.cost && [
|
||||
{
|
||||
input: info.cost.input,
|
||||
|
|
@ -203,7 +211,6 @@ function migrateModel(info: typeof ConfigProviderV1.Model.Type, packageName?: st
|
|||
info.tool_call !== undefined || info.modalities?.input !== undefined || info.modalities?.output !== undefined
|
||||
? { tools: info.tool_call ?? false, input: info.modalities?.input ?? [], output: info.modalities?.output ?? [] }
|
||||
: undefined
|
||||
const lowerer = ConfigProviderOptionsV1.get(info.provider?.npm ?? packageName)
|
||||
return {
|
||||
family: info.family,
|
||||
name: info.name,
|
||||
|
|
@ -219,12 +226,16 @@ function migrateModel(info: typeof ConfigProviderV1.Model.Type, packageName?: st
|
|||
? undefined
|
||||
: { id: info.id },
|
||||
capabilities,
|
||||
request: (info.headers || info.options) && {
|
||||
request: (info.headers || request) && {
|
||||
headers: info.headers,
|
||||
body: info.options && lowerer.request(info.options),
|
||||
body: request,
|
||||
},
|
||||
variants:
|
||||
info.variants && Object.entries(info.variants).map(([id, options]) => ({ id, body: lowerer.request(options) })),
|
||||
info.variants &&
|
||||
Object.entries(info.variants).map(([id, options]) => ({
|
||||
id,
|
||||
body: ingest(options),
|
||||
})),
|
||||
cost: costs,
|
||||
disabled: info.status === "deprecated" ? true : undefined,
|
||||
limit: info.limit && {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue