Spaces:
Runtime error
Runtime error
Update ai-routes.js
Browse files- ai-routes.js +5 -6
ai-routes.js
CHANGED
|
@@ -83,7 +83,7 @@ function convertGeminiToDoubaoInput(baseParams) {
|
|
| 83 |
// 1. System Prompt
|
| 84 |
const sysInstruction = baseParams.config?.systemInstruction || baseParams.systemInstruction;
|
| 85 |
if (sysInstruction) {
|
| 86 |
-
// Doubao Bot API: System role
|
| 87 |
inputs.push({
|
| 88 |
role: 'system',
|
| 89 |
content: [{ type: 'input_text', text: sysInstruction }]
|
|
@@ -101,8 +101,9 @@ function convertGeminiToDoubaoInput(baseParams) {
|
|
| 101 |
let role = (content.role === 'model' || content.role === 'assistant') ? 'assistant' : 'user';
|
| 102 |
|
| 103 |
// STRICT TYPE MAPPING:
|
| 104 |
-
// User -> input_text
|
| 105 |
// Assistant -> output_text
|
|
|
|
| 106 |
const textType = role === 'assistant' ? 'output_text' : 'input_text';
|
| 107 |
|
| 108 |
const contentParts = [];
|
|
@@ -113,9 +114,6 @@ function convertGeminiToDoubaoInput(baseParams) {
|
|
| 113 |
contentParts.push({ type: textType, text: p.text });
|
| 114 |
}
|
| 115 |
else if (p.inlineData && p.inlineData.mimeType.startsWith('image/')) {
|
| 116 |
-
// Doubao Image: Usually 'image_url' is supported in V3,
|
| 117 |
-
// but strictly check if your endpoint supports multimodal.
|
| 118 |
-
// Assuming standard image_url for now.
|
| 119 |
contentParts.push({ type: 'image_url', image_url: { url: `data:${p.inlineData.mimeType};base64,${p.inlineData.data}` } });
|
| 120 |
}
|
| 121 |
});
|
|
@@ -261,7 +259,8 @@ async function streamDoubao(baseParams, res, username, mode = 'chat', config, en
|
|
| 261 |
// Add ID if valid
|
| 262 |
...(idToSend && { previous_response_id: idToSend }),
|
| 263 |
// Add Search Tools if enabled
|
| 264 |
-
|
|
|
|
| 265 |
};
|
| 266 |
|
| 267 |
console.log(`[AI] 🚀 Doubao Request Details:
|
|
|
|
| 83 |
// 1. System Prompt
|
| 84 |
const sysInstruction = baseParams.config?.systemInstruction || baseParams.systemInstruction;
|
| 85 |
if (sysInstruction) {
|
| 86 |
+
// Doubao Bot API: System role content is array of objects, type MUST be "input_text"
|
| 87 |
inputs.push({
|
| 88 |
role: 'system',
|
| 89 |
content: [{ type: 'input_text', text: sysInstruction }]
|
|
|
|
| 101 |
let role = (content.role === 'model' || content.role === 'assistant') ? 'assistant' : 'user';
|
| 102 |
|
| 103 |
// STRICT TYPE MAPPING:
|
| 104 |
+
// User/System -> input_text
|
| 105 |
// Assistant -> output_text
|
| 106 |
+
// Using "text" will cause 400 Bad Request
|
| 107 |
const textType = role === 'assistant' ? 'output_text' : 'input_text';
|
| 108 |
|
| 109 |
const contentParts = [];
|
|
|
|
| 114 |
contentParts.push({ type: textType, text: p.text });
|
| 115 |
}
|
| 116 |
else if (p.inlineData && p.inlineData.mimeType.startsWith('image/')) {
|
|
|
|
|
|
|
|
|
|
| 117 |
contentParts.push({ type: 'image_url', image_url: { url: `data:${p.inlineData.mimeType};base64,${p.inlineData.data}` } });
|
| 118 |
}
|
| 119 |
});
|
|
|
|
| 259 |
// Add ID if valid
|
| 260 |
...(idToSend && { previous_response_id: idToSend }),
|
| 261 |
// Add Search Tools if enabled
|
| 262 |
+
// CORRECTION: 'tools' list contains object with 'type': 'web_search'. NO nested 'web_search' config object inside.
|
| 263 |
+
...(enableSearch && { tools: [{ type: "web_search" }] })
|
| 264 |
};
|
| 265 |
|
| 266 |
console.log(`[AI] 🚀 Doubao Request Details:
|