MODEL_CAPS
This commit is contained in:
@@ -51,11 +51,38 @@ function ensureInitialized() {
|
||||
require("./response/ollama-to-openai.js");
|
||||
}
|
||||
|
||||
// Strip multimodal content blocks (image/audio/video) from messages if model doesn't support them
|
||||
function stripUnsupportedMultimodal(body, multimodal = {}) {
|
||||
if (!body.messages || !Array.isArray(body.messages)) return;
|
||||
for (const msg of body.messages) {
|
||||
if (!Array.isArray(msg.content)) continue;
|
||||
msg.content = msg.content.filter(part => {
|
||||
if (part.type === "image_url" || part.type === "image") return multimodal.image === true;
|
||||
if (part.type === "audio_url" || part.type === "input_audio") return multimodal.audio === true;
|
||||
return true; // keep text, tool_use, tool_result, etc.
|
||||
});
|
||||
// If content array becomes empty after filtering, replace with empty string to avoid API errors
|
||||
if (msg.content.length === 0) msg.content = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Translate request: source -> openai -> target
|
||||
export function translateRequest(sourceFormat, targetFormat, model, body, stream = true, credentials = null, provider = null, reqLogger = null) {
|
||||
export function translateRequest(sourceFormat, targetFormat, model, body, stream = true, credentials = null, provider = null, reqLogger = null, caps = null) {
|
||||
ensureInitialized();
|
||||
let result = body;
|
||||
|
||||
// Apply model capability guards before translation
|
||||
if (caps) {
|
||||
// Strip multimodal content if model doesn't support it
|
||||
stripUnsupportedMultimodal(result, caps.multimodal || {});
|
||||
|
||||
// Strip thinking config if model doesn't support thinking
|
||||
if (!caps.thinking) {
|
||||
delete result.thinking;
|
||||
delete result.reasoning_effort;
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize thinking config: remove if lastMessage is not user
|
||||
normalizeThinkingConfig(result);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user