82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
type ModelCompatDescriptor = {
|
|
providerType?: string | null;
|
|
providerBaseUrl?: string | null;
|
|
modelId?: string | null;
|
|
displayName?: string | null;
|
|
provider?: {
|
|
type?: string | null;
|
|
baseUrl?: string | null;
|
|
} | null;
|
|
model?: {
|
|
modelId?: string | null;
|
|
displayName?: string | null;
|
|
} | null;
|
|
};
|
|
|
|
const KIMI_MODEL_PATTERN = /\bkimi(?:[-_.\s]?[a-z0-9.]+)?\b/i;
|
|
|
|
function normalizeProviderType(input: ModelCompatDescriptor): string {
|
|
return String(input.providerType || input.provider?.type || "")
|
|
.trim()
|
|
.toLowerCase();
|
|
}
|
|
|
|
function normalizeProviderBaseUrl(input: ModelCompatDescriptor): string {
|
|
return String(input.providerBaseUrl || input.provider?.baseUrl || "")
|
|
.trim()
|
|
.toLowerCase();
|
|
}
|
|
|
|
function normalizeModelText(input: ModelCompatDescriptor): string {
|
|
return `${String(input.displayName || input.model?.displayName || "")} ${String(input.modelId || input.model?.modelId || "")}`
|
|
.trim()
|
|
.toLowerCase();
|
|
}
|
|
|
|
export function isMoonshotKimiModel(
|
|
input?: ModelCompatDescriptor | null,
|
|
): boolean {
|
|
if (!input) {
|
|
return false;
|
|
}
|
|
|
|
const providerType = normalizeProviderType(input);
|
|
const providerBaseUrl = normalizeProviderBaseUrl(input);
|
|
const modelText = normalizeModelText(input);
|
|
|
|
if (providerType.includes("moonshot")) {
|
|
return true;
|
|
}
|
|
|
|
if (providerBaseUrl.includes("moonshot.cn")) {
|
|
return true;
|
|
}
|
|
|
|
if (modelText.includes("moonshot")) {
|
|
return true;
|
|
}
|
|
|
|
if (KIMI_MODEL_PATTERN.test(modelText)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
export function getCompatibleTextGenerationTemperature(
|
|
input: ModelCompatDescriptor | null | undefined,
|
|
preferredTemperature?: number,
|
|
): number | undefined {
|
|
if (isMoonshotKimiModel(input)) {
|
|
return 1;
|
|
}
|
|
|
|
return preferredTemperature;
|
|
}
|
|
|
|
export function shouldForceInlineVisionInputs(
|
|
input: ModelCompatDescriptor | null | undefined,
|
|
): boolean {
|
|
return isMoonshotKimiModel(input);
|
|
}
|