Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"huggingface:sync": "bun ./packages/core/script/sync-models.ts huggingface",
"kilo:sync": "bun ./packages/core/script/sync-models.ts kilo",
"llmgateway:sync": "bun ./packages/core/script/sync-models.ts llmgateway",
"llmgateway-providers:sync": "bun ./packages/core/script/sync-models.ts llmgateway-providers",
"requesty:sync": "bun ./packages/core/script/sync-models.ts requesty",
"merge-gateway:sync": "bun ./packages/core/script/sync-models.ts merge-gateway",
"nano-gpt:sync": "bun ./packages/core/script/sync-models.ts nano-gpt",
Expand Down
29 changes: 25 additions & 4 deletions packages/core/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { google } from "./providers/google.js";
import { hyper } from "./providers/hyper.js";
import { huggingface } from "./providers/huggingface.js";
import { kilo } from "./providers/kilo.js";
import { llmgateway } from "./providers/llmgateway.js";
import { llmgateway, llmgatewayProviders } from "./providers/llmgateway.js";
import { mergeGateway } from "./providers/merge-gateway.js";
import { nanoGpt } from "./providers/nano-gpt.js";
import { openai } from "./providers/openai.js";
Expand Down Expand Up @@ -96,7 +96,17 @@ export interface SyncProvider<SourceModel> {
existing(id: string): ExistingModel | undefined;
authored(id: string): ExistingModel | undefined;
},
): { id: string; model: SyncedModel; metadata?: { id: string; model: SyncedMetadata } } | undefined;
): {
id: string;
model: SyncedModel;
metadata?: { id: string; model: SyncedMetadata };
/**
* Leading comment block for the written file when it has none of its own
* (e.g. the wire-path header every toggle reasoning control requires). A
* header already present on the existing file always wins.
*/
header?: string;
} | undefined;
}

export interface SyncResult {
Expand Down Expand Up @@ -127,6 +137,7 @@ export const providers: {
huggingface: SyncProvider<any>;
kilo: SyncProvider<any>;
llmgateway: SyncProvider<any>;
"llmgateway-providers": SyncProvider<any>;
"merge-gateway": SyncProvider<any>;
"nano-gpt": SyncProvider<any>;
ofox: SyncProvider<any>;
Expand Down Expand Up @@ -156,6 +167,7 @@ export const providers: {
huggingface,
kilo,
llmgateway,
"llmgateway-providers": llmgatewayProviders,
"merge-gateway": mergeGateway,
"nano-gpt": nanoGpt,
ofox,
Expand All @@ -178,6 +190,7 @@ export const groups = {
"huggingface",
"kilo",
"llmgateway",
"llmgateway-providers",
"merge-gateway",
"nano-gpt",
"ofox",
Expand Down Expand Up @@ -262,13 +275,16 @@ export async function syncProvider<SourceModel>(
: preserveBaseModel(translated.model, existing.get(relativePath)?.authored);
const translatedBase = "base_model" in translatedModel ? translatedModel.base_model : undefined;
let resolvedReasoning: boolean | undefined;
let baseReasoningOptions: unknown;
if (translatedBase !== undefined) {
if (translated.metadata?.id === translatedBase) {
resolvedReasoning = translated.metadata.model.reasoning;
baseReasoningOptions = translated.metadata.model.reasoning_options;
} else {
modelMetadata ??= await readModelMetadata(provider.modelsDir);
const canonicalReasoning = modelMetadata[translatedBase]?.reasoning;
resolvedReasoning = typeof canonicalReasoning === "boolean" ? canonicalReasoning : undefined;
baseReasoningOptions = modelMetadata[translatedBase]?.reasoning_options;
}
} else {
resolvedReasoning = existing.get(relativePath)?.toml.reasoning;
Expand All @@ -277,6 +293,7 @@ export async function syncProvider<SourceModel>(
translatedModel,
existing.get(relativePath)?.authored,
resolvedReasoning,
baseReasoningOptions,
);
const withDescription = provider.preserveDescriptions === false
? withReasoningOptions
Expand All @@ -292,7 +309,7 @@ export async function syncProvider<SourceModel>(

desired.set(relativePath, {
model: parsed.data,
content: (existing.get(relativePath)?.header ?? "") + formatToml(parsed.data),
content: ((existing.get(relativePath)?.header || translated.header) ?? "") + formatToml(parsed.data),
});
}

Expand Down Expand Up @@ -468,14 +485,18 @@ export function preserveReasoningOptions(
model: SyncedModel,
existing: ExistingModel | undefined,
resolvedReasoning: boolean | undefined = existing?.reasoning,
baseReasoningOptions: unknown = undefined,
): SyncedModel {
if ((model.reasoning ?? resolvedReasoning) === false) {
const { reasoning_options: _reasoningOptions, ...withoutReasoningOptions } = model;
return withoutReasoningOptions as SyncedModel;
}
if (model.reasoning_options !== undefined) return model;
if (existing?.reasoning_options === undefined) {
return (model.reasoning ?? resolvedReasoning) === true
// When the base model already declares reasoning_options, leave the field
// unset so the factored file inherits them — stamping [] here would
// shadow the base's real controls with "no controls".
return (model.reasoning ?? resolvedReasoning) === true && baseReasoningOptions === undefined
? { ...model, reasoning_options: [] }
: model;
}
Expand Down
Loading
Loading