|
|
|
@@ -61,9 +61,11 @@ import {
|
|
|
|
|
type DiscoveryProviderConfig,
|
|
|
|
|
discoverLlamaCppModelRuntimeMetadata,
|
|
|
|
|
discoverModelsByProviderType,
|
|
|
|
|
ensureLlamaCppV1BaseUrl,
|
|
|
|
|
getImplicitOllamaBaseUrl,
|
|
|
|
|
getOllamaContextLengthOverride,
|
|
|
|
|
normalizeLiteLLMDiscoveryBaseUrl,
|
|
|
|
|
normalizeLlamaCppBaseUrl,
|
|
|
|
|
} from "./model-discovery";
|
|
|
|
|
import {
|
|
|
|
|
AUTHORITATIVE_RUNTIME_CATALOG_PROVIDERS,
|
|
|
|
@@ -577,7 +579,7 @@ export class ModelRegistry {
|
|
|
|
|
const withConfigModels = this.#mergeCustomModels(resolvedDefaults, select(this.#customModelOverlays));
|
|
|
|
|
const combined = this.#mergeCustomModels(withConfigModels, select(this.#runtimeModelOverlays));
|
|
|
|
|
const withModelOverrides = this.#applyModelOverrides(collapseBuiltModelVariants(combined), this.#modelOverrides);
|
|
|
|
|
return this.#applyLlamaCppQwenThinkingToModels(this.#applyRuntimeProviderOverrides(withModelOverrides));
|
|
|
|
|
return this.#applyLlamaCppModelFixups(this.#applyRuntimeProviderOverrides(withModelOverrides));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#composeStaticModels(providerFilter?: ReadonlySet<string>): Model<Api>[] {
|
|
|
|
@@ -1064,9 +1066,7 @@ export class ModelRegistry {
|
|
|
|
|
const withConfigModels = this.#mergeCustomModels(resolved, this.#customModelOverlays);
|
|
|
|
|
const combined = this.#mergeCustomModels(withConfigModels, this.#runtimeModelOverlays);
|
|
|
|
|
const withModelOverrides = this.#applyModelOverrides(collapseBuiltModelVariants(combined), this.#modelOverrides);
|
|
|
|
|
this.#unprojectedModels = this.#applyLlamaCppQwenThinkingToModels(
|
|
|
|
|
this.#applyRuntimeProviderOverrides(withModelOverrides),
|
|
|
|
|
);
|
|
|
|
|
this.#unprojectedModels = this.#applyLlamaCppModelFixups(this.#applyRuntimeProviderOverrides(withModelOverrides));
|
|
|
|
|
this.#models = this.#applyRuntimeModelModifiers(this.#unprojectedModels);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1446,20 +1446,28 @@ export class ModelRegistry {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// #applyLlamaCppQwenThinkingToModels re-runs applyLlamaCppQwenThinking as the
|
|
|
|
|
// outermost transform for llama.cpp-provider models, after discovery merges,
|
|
|
|
|
// cache fallbacks, and provider/transport overrides have run. It is
|
|
|
|
|
// idempotent, so it restores the routed Qwen model's chat-completions api,
|
|
|
|
|
// `/v1` runtime base URL, and disable dialect even when a configured `baseUrl`
|
|
|
|
|
// override (which wins in mergeDiscoveredModel) or a fallback to a pre-fix
|
|
|
|
|
// cached row would otherwise leave the old spec in place.
|
|
|
|
|
#applyLlamaCppQwenThinkingToModels(models: Model<Api>[]): Model<Api>[] {
|
|
|
|
|
// #applyLlamaCppModelFixups is the outermost transform for llama.cpp-provider
|
|
|
|
|
// models, after discovery merges, cache fallbacks, and provider/transport
|
|
|
|
|
// overrides have run. It applies Qwen-specific fixes (api, reasoning, compat)
|
|
|
|
|
// and ensures all non-transport models have the `/v1` prefix in their baseUrl,
|
|
|
|
|
// even when a configured override or stale cache row would strip it.
|
|
|
|
|
#applyLlamaCppModelFixups(models: Model<Api>[]): Model<Api>[] {
|
|
|
|
|
const llamaCppProviders = new Set<string>();
|
|
|
|
|
for (const provider of this.#discoverableProviders) {
|
|
|
|
|
if (provider.discovery.type === "llama.cpp") llamaCppProviders.add(provider.provider);
|
|
|
|
|
}
|
|
|
|
|
if (llamaCppProviders.size === 0) return models;
|
|
|
|
|
return models.map(model => (llamaCppProviders.has(model.provider) ? applyLlamaCppQwenThinking(model) : model));
|
|
|
|
|
return models.map(model => {
|
|
|
|
|
if (!llamaCppProviders.has(model.provider)) return model;
|
|
|
|
|
const withFixups = applyLlamaCppQwenThinking(model);
|
|
|
|
|
if (!withFixups.transport && !withFixups.baseUrl.endsWith("/v1")) {
|
|
|
|
|
return buildModel({
|
|
|
|
|
...withFixups,
|
|
|
|
|
baseUrl: ensureLlamaCppV1BaseUrl(normalizeLlamaCppBaseUrl(withFixups.baseUrl)),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return withFixups;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#mergeProviderOverride(baseOverride: ProviderOverride | undefined, override: ProviderOverride): ProviderOverride {
|
|
|
|
@@ -2102,7 +2110,7 @@ export class ModelRegistry {
|
|
|
|
|
transportOverride,
|
|
|
|
|
);
|
|
|
|
|
this.#runtimeProviderOverrides.set(providerName, nextRuntimeOverride);
|
|
|
|
|
this.#unprojectedModels = this.#applyLlamaCppQwenThinkingToModels(
|
|
|
|
|
this.#unprojectedModels = this.#applyLlamaCppModelFixups(
|
|
|
|
|
this.#unprojectedModels.map(model => {
|
|
|
|
|
if (model.provider !== providerName) return model;
|
|
|
|
|
return this.#applyProviderTransportOverrideToModel(model, transportOverride);
|
|
|
|
|