148 lines
3.9 KiB
TypeScript
148 lines
3.9 KiB
TypeScript
export type ImportedModelModality = 'text' | 'audio' | 'image' | 'pdf';
|
|
export type ImportedVisionTokenEstimator = 'qwen-32px-grid';
|
|
export type ImportedThinkingLevel = 'off' | 'minimal' | 'low' | 'medium' | 'high';
|
|
|
|
export interface ImportedPiModelProfile {
|
|
reasoning: boolean;
|
|
thinkingLevelMap?: Partial<Record<ImportedThinkingLevel, string | null>>;
|
|
compat?: {
|
|
thinkingFormat?: 'deepseek' | 'openrouter' | 'qwen';
|
|
supportsDeveloperRole?: boolean;
|
|
supportsReasoningEffort?: boolean;
|
|
supportsStore?: boolean;
|
|
requiresReasoningContentOnAssistantMessages?: boolean;
|
|
};
|
|
}
|
|
|
|
export interface ImportedModelProfile {
|
|
modalities: {
|
|
input: ImportedModelModality[];
|
|
output: ImportedModelModality[];
|
|
};
|
|
limit?: {
|
|
context: number;
|
|
output: number;
|
|
};
|
|
visionTokenEstimator?: ImportedVisionTokenEstimator;
|
|
pi?: ImportedPiModelProfile;
|
|
}
|
|
|
|
const VERIFIED_QWEN_36_PLUS_MODEL_IDS = new Set([
|
|
'qwen3.6-plus',
|
|
'qwen3.6-plus-2026-04-02',
|
|
]);
|
|
const VERIFIED_QWEN_PLUS_MODEL_IDS = new Set([
|
|
...VERIFIED_QWEN_36_PLUS_MODEL_IDS,
|
|
'qwen3.7-plus',
|
|
'qwen3.7-plus-2026-05-26',
|
|
]);
|
|
const QWEN_VL_PATTERN = /^qwen(?:\d+(?:\.\d+)?)?-vl(?:[-\w.]+)?$/i;
|
|
const QWEN_OMNI_PATTERN = /^qwen-omni(?:[-\w.]+)?$/i;
|
|
|
|
function imageModalities(): ImportedModelProfile['modalities'] {
|
|
return {
|
|
input: ['text', 'image'],
|
|
output: ['text'],
|
|
};
|
|
}
|
|
|
|
export function getImportedModelProfile(rawModelId: string): ImportedModelProfile | null {
|
|
const modelId = rawModelId.trim();
|
|
const normalizedModelId = modelId.toLowerCase();
|
|
if (normalizedModelId === 'deepseek-v4-pro') {
|
|
return {
|
|
modalities: {
|
|
input: ['text'],
|
|
output: ['text'],
|
|
},
|
|
limit: {
|
|
context: 1_000_000,
|
|
output: 384_000,
|
|
},
|
|
pi: {
|
|
reasoning: true,
|
|
thinkingLevelMap: {
|
|
off: null,
|
|
minimal: null,
|
|
low: null,
|
|
medium: null,
|
|
high: 'high',
|
|
},
|
|
compat: {
|
|
thinkingFormat: 'deepseek',
|
|
requiresReasoningContentOnAssistantMessages: true,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
if (normalizedModelId === 'qwen3.8-max') {
|
|
return {
|
|
modalities: imageModalities(),
|
|
limit: {
|
|
context: 1_000_000,
|
|
output: 131_072,
|
|
},
|
|
pi: {
|
|
reasoning: true,
|
|
thinkingLevelMap: {
|
|
minimal: null,
|
|
low: 'low',
|
|
medium: 'medium',
|
|
high: 'xhigh',
|
|
},
|
|
compat: {
|
|
thinkingFormat: 'qwen',
|
|
supportsDeveloperRole: false,
|
|
supportsReasoningEffort: true,
|
|
supportsStore: false,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
if (VERIFIED_QWEN_PLUS_MODEL_IDS.has(normalizedModelId)) {
|
|
return {
|
|
modalities: imageModalities(),
|
|
limit: {
|
|
context: 1_000_000,
|
|
output: 65_536,
|
|
},
|
|
visionTokenEstimator: 'qwen-32px-grid',
|
|
...(VERIFIED_QWEN_36_PLUS_MODEL_IDS.has(normalizedModelId)
|
|
? {
|
|
pi: {
|
|
reasoning: true,
|
|
thinkingLevelMap: {
|
|
minimal: null,
|
|
low: null,
|
|
medium: null,
|
|
high: 'high',
|
|
},
|
|
compat: {
|
|
thinkingFormat: 'qwen' as const,
|
|
supportsDeveloperRole: false,
|
|
supportsReasoningEffort: false,
|
|
supportsStore: false,
|
|
},
|
|
},
|
|
}
|
|
: {}),
|
|
};
|
|
}
|
|
if (QWEN_VL_PATTERN.test(modelId) || QWEN_OMNI_PATTERN.test(modelId)) {
|
|
return {
|
|
modalities: imageModalities(),
|
|
};
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function estimateImportedModelVisionTokens(
|
|
modelId: string,
|
|
width: number,
|
|
height: number,
|
|
): number | null {
|
|
if (getImportedModelProfile(modelId)?.visionTokenEstimator !== 'qwen-32px-grid') return null;
|
|
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) return null;
|
|
return Math.ceil((width * height) / (32 * 32)) + 2;
|
|
}
|