|
|
|
@@ -1,3 +1,5 @@
|
|
|
|
|
import { officialModelParameters } from './official-model-parameters.mjs';
|
|
|
|
|
|
|
|
|
|
export const reasoningEfforts = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
|
|
|
export const messagesEfforts = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
|
|
|
const labels = { auto: '自动匹配', openai: 'OpenAI 兼容', anthropic: 'Claude Messages 兼容', deepseek: 'DeepSeek 兼容' };
|
|
|
|
@@ -14,55 +16,86 @@ export function parameterProfileSettings(protocol, value = 'auto') {
|
|
|
|
|
|
|
|
|
|
// A profile describes the adapter's fields. It is not evidence that a vendor,
|
|
|
|
|
// proxy or particular model supports every field in that protocol.
|
|
|
|
|
function declaredChoices(metadata, field, supportField, feature, fallback, official) {
|
|
|
|
|
if (metadata?.features?.[feature] === 'unsupported') return [];
|
|
|
|
|
const values = metadata?.[field] ?? [], support = metadata?.[supportField];
|
|
|
|
|
if (support && Object.values(support).some(value => value !== 'unknown')) {
|
|
|
|
|
return [...new Set([...fallback, ...values, ...Object.keys(support)])].filter(value => support[value] === 'supported'
|
|
|
|
|
|| support[value] !== 'unsupported' && (values.includes(value) || official && fallback.includes(value)));
|
|
|
|
|
}
|
|
|
|
|
return values.length ? values : fallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function modelParameterProfile(connection) {
|
|
|
|
|
const protocol = connection.protocol ?? 'chat-completions';
|
|
|
|
|
const selected = parameterProfileSettings(protocol, connection.parameterProfile);
|
|
|
|
|
const official = selected === 'auto' && protocol === 'anthropic-messages' ? officialModelParameters(connection.model) : null;
|
|
|
|
|
const deepseek = connection.brand === 'DeepSeek' || /^deepseek(?:-|$)/i.test(connection.model ?? '')
|
|
|
|
|
|| /^https:\/\/api\.deepseek\.com(?:\/|$)/i.test(connection.baseUrl ?? '') || !!connection.nativeParameters?.thinking && protocol === 'chat-completions';
|
|
|
|
|
const id = selected !== 'auto' ? selected : deepseek ? 'deepseek' : protocol === 'anthropic-messages' ? 'anthropic' : 'openai';
|
|
|
|
|
const metadata = connection.upstreamModel;
|
|
|
|
|
const id = selected !== 'auto' ? selected : official ? 'anthropic' : deepseek ? 'deepseek' : protocol === 'anthropic-messages' ? 'anthropic' : 'openai';
|
|
|
|
|
const metadata = !connection.model || connection.upstreamModel?.id === connection.model ? connection.upstreamModel : null;
|
|
|
|
|
const choices = id === 'deepseek' ? ['low', 'high', 'max'] : protocol === 'anthropic-messages' ? messagesEfforts : reasoningEfforts.filter(value => value !== 'none');
|
|
|
|
|
return { id, label: labels[id], source: selected === 'auto' ? '按品牌、型号与协议匹配,可手动更改' : '用户选择的兼容格式',
|
|
|
|
|
efforts: metadata?.features?.effort === 'unsupported' ? [] : metadata?.efforts?.length ? choices.filter(value => metadata.efforts.includes(value)) : choices,
|
|
|
|
|
modes: metadata?.features?.thinking === 'unsupported' ? [] : metadata?.modes?.length ? metadata.modes : ['disabled', 'enabled', ...(protocol === 'anthropic-messages' ? ['adaptive'] : [])],
|
|
|
|
|
const modes = official?.modes ?? ['disabled', 'enabled', ...(protocol === 'anthropic-messages' ? ['adaptive', 'between_tools'] : [])];
|
|
|
|
|
return { id, label: labels[id], source: metadata ? '优先采用相符型号的上游目录声明,缺失项再匹配官方规格或兼容格式'
|
|
|
|
|
: official ? '按 Anthropic 官方精确型号规格匹配' : selected === 'auto' ? '按品牌、型号与协议匹配;未取得的型号能力待确认' : '用户选择的兼容格式,不套用官方型号后备选项',
|
|
|
|
|
sourceKind: metadata ? 'upstream_model_list' : official ? 'official_model_spec' : 'compatibility_profile',
|
|
|
|
|
officialSource: official ? { url: official.sourceUrl, effortUrl: official.effortSourceUrl, checkedAt: official.checkedAt } : null,
|
|
|
|
|
efforts: declaredChoices(metadata, 'efforts', 'effortSupport', 'effort', official?.efforts ?? choices, !!official),
|
|
|
|
|
modes: declaredChoices(metadata, 'modes', 'modeSupport', 'thinking', modes, !!official),
|
|
|
|
|
modeEfforts: official?.modeEfforts ?? {}, defaultMode: official?.defaultMode ?? null, defaultEffort: official?.defaultEffort ?? null,
|
|
|
|
|
thinking: protocol === 'anthropic-messages' || id === 'deepseek' && protocol === 'chat-completions' };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function assertModelParameterSupport(connection, parameters) {
|
|
|
|
|
const metadata = connection.upstreamModel;
|
|
|
|
|
const metadata = !connection.model || connection.upstreamModel?.id === connection.model ? connection.upstreamModel : null;
|
|
|
|
|
if (!metadata) return;
|
|
|
|
|
const effort = parameters.reasoning_effort ?? parameters.reasoning?.effort ?? parameters.output_config?.effort;
|
|
|
|
|
const mode = parameters.thinking?.type;
|
|
|
|
|
if (effort && (metadata.features?.effort === 'unsupported' || effort !== 'none' && metadata.efforts?.length && !metadata.efforts.includes(effort)))
|
|
|
|
|
if (effort && (metadata.features?.effort === 'unsupported' || metadata.effortSupport?.[effort] === 'unsupported' || effort !== 'none' && metadata.efforts?.length && !metadata.efforts.includes(effort)))
|
|
|
|
|
throw Object.assign(new Error('上游目录声明该型号不支持所选推理强度,请选择支持的档位或保留默认。'), { status: 400 });
|
|
|
|
|
if (mode && (metadata.features?.thinking === 'unsupported' || metadata.modes?.length && !metadata.modes.includes(mode)))
|
|
|
|
|
if (mode && (metadata.features?.thinking === 'unsupported' || metadata.modeSupport?.[mode] === 'unsupported' || metadata.modes?.length && !metadata.modes.includes(mode)))
|
|
|
|
|
throw Object.assign(new Error('上游目录声明该型号不支持所选推理模式,请选择支持的模式或保留默认。'), { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function reasoningSetting(connection, parameters) {
|
|
|
|
|
const profile = modelParameterProfile(connection), protocol = connection.protocol;
|
|
|
|
|
const effort = protocol === 'anthropic-messages' ? parameters.output_config?.effort : protocol === 'responses' ? parameters.reasoning?.effort : parameters.reasoning_effort;
|
|
|
|
|
const thinkingSiblings = parameters.thinking && Object.keys(parameters.thinking).some(key => !['type', 'budget_tokens'].includes(key));
|
|
|
|
|
return { mode: profile.thinking ? parameters.thinking?.type ?? 'default' : effort === 'none' ? 'disabled' : effort ? 'enabled' : 'default',
|
|
|
|
|
effort: effort === 'none' ? '' : effort ?? '', budget: parameters.thinking?.budget_tokens ?? 1024 };
|
|
|
|
|
effort: effort === 'none' ? '' : effort ?? '', budget: parameters.thinking?.budget_tokens ?? 1024,
|
|
|
|
|
canResetMode: !profile.thinking || !thinkingSiblings || !!profile.defaultMode && profile.modes.includes(profile.defaultMode), thinkingSiblings: !!thinkingSiblings };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function changeReasoningSetting(connection, parameters, field, value) {
|
|
|
|
|
const next = structuredClone(parameters), profile = modelParameterProfile(connection), protocol = connection.protocol;
|
|
|
|
|
const effortField = protocol === 'anthropic-messages' ? 'output_config' : protocol === 'responses' ? 'reasoning' : 'reasoning_effort';
|
|
|
|
|
const editObject = (key, updates, remove = []) => {
|
|
|
|
|
const original = next[key], updated = { ...(original && typeof original === 'object' && !Array.isArray(original) ? original : {}), ...updates };
|
|
|
|
|
for (const name of remove) delete updated[name];
|
|
|
|
|
if (Object.keys(updated).length) next[key] = updated; else delete next[key];
|
|
|
|
|
};
|
|
|
|
|
const setEffort = effort => {
|
|
|
|
|
if (!effort) delete next[effortField];
|
|
|
|
|
else next[effortField] = effortField === 'reasoning_effort' ? effort : { effort };
|
|
|
|
|
if (effortField !== 'reasoning_effort') editObject(effortField, effort ? { effort } : {}, effort ? [] : ['effort']);
|
|
|
|
|
else if (effort) next[effortField] = effort; else delete next[effortField];
|
|
|
|
|
};
|
|
|
|
|
if (field === 'effort') setEffort(value);
|
|
|
|
|
else if (field === 'budget') next.thinking = { type: 'enabled', budget_tokens: value };
|
|
|
|
|
else if (field === 'budget') editObject('thinking', { type: 'enabled', budget_tokens: value });
|
|
|
|
|
else if (field === 'mode') {
|
|
|
|
|
if (value === 'default') { delete next.thinking; setEffort(''); }
|
|
|
|
|
if (value === 'default') {
|
|
|
|
|
if (!profile.thinking) setEffort('');
|
|
|
|
|
else {
|
|
|
|
|
const setting = reasoningSetting(connection, parameters);
|
|
|
|
|
// A thinking object with display/other options still requires type.
|
|
|
|
|
// Use an exact known default, or leave the configuration intact.
|
|
|
|
|
if (setting.canResetMode) editObject('thinking', setting.thinkingSiblings ? { type: profile.defaultMode } : {},
|
|
|
|
|
setting.thinkingSiblings ? ['budget_tokens'] : ['type', 'budget_tokens']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (profile.thinking) {
|
|
|
|
|
next.thinking = value === 'enabled' && protocol === 'anthropic-messages'
|
|
|
|
|
? { type: value, budget_tokens: parameters.thinking?.budget_tokens ?? 1024 } : { type: value };
|
|
|
|
|
if (value === 'disabled') setEffort('');
|
|
|
|
|
editObject('thinking', value === 'enabled' && protocol === 'anthropic-messages'
|
|
|
|
|
? { type: value, budget_tokens: parameters.thinking?.budget_tokens ?? 1024 } : { type: value },
|
|
|
|
|
value === 'enabled' && protocol === 'anthropic-messages' ? [] : ['budget_tokens']);
|
|
|
|
|
} else {
|
|
|
|
|
delete next.thinking;
|
|
|
|
|
setEffort(value === 'disabled' ? 'none' : reasoningSetting(connection, parameters).effort || (profile.efforts.includes('medium') ? 'medium' : profile.efforts[0] ?? ''));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -76,9 +109,9 @@ export function modelFeatureRows(connection) {
|
|
|
|
|
{ name: '文本 / 工具调用', upstream: declared('text') + ' / ' + declared('tools'), local: '已接入,可单独检测' },
|
|
|
|
|
{ name: '流式输出', upstream: declared('streaming'), local: '已接入,按连接开关发送' },
|
|
|
|
|
{ name: '图像输入', upstream: declared('vision'), local: '已接入 PNG,可单独检测' },
|
|
|
|
|
{ name: '推理模式 / 强度', upstream: connection.upstreamModel ? `${states[connection.upstreamModel.features?.thinking ?? 'unknown']} / ${connection.upstreamModel.efforts?.join('、') || states[connection.upstreamModel.features?.effort ?? 'unknown']}` : '依型号与兼容服务支持范围', local: '按配置档发送,受原输出预算约束' },
|
|
|
|
|
{ name: '推理模式 / 强度', upstream: modelParameterProfile(connection).source, local: '按原生字段发送;本地默认不限,协议条件以上游为准' },
|
|
|
|
|
{ name: '语音 / 视频 / 服务端工具', upstream: '需供应商提供相应协议', local: '尚未接入' },
|
|
|
|
|
{ name: '结构化输出约束', upstream: states[connection.upstreamModel?.features?.structured_outputs ?? 'unknown'], local: '尚未接入,参数保存时明确拒绝' },
|
|
|
|
|
{ name: '结构化输出约束', upstream: states[connection.upstreamModel?.features?.structured_outputs ?? 'unknown'], local: '开放模式可透传约束参数;完整结果校验流程待接入' },
|
|
|
|
|
...(connection.upstreamModel ? [{ name: 'PDF / 服务端工具 / 批处理', upstream: ['pdf_input', 'server_tools', 'batch'].map(key => states[connection.upstreamModel.features?.[key] ?? 'unknown']).join(' / '), local: '目录声明已同步,执行能力尚未接入' }] : []),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|