Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -126,7 +126,26 @@ app.post('/api/generate', async (req, res) => {
|
|
| 126 |
});
|
| 127 |
|
| 128 |
const response = await bedrockClient.send(command);
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
const tokenUsage = response.usage ? (response.usage.inputTokens + response.usage.outputTokens) : 0;
|
| 131 |
|
| 132 |
res.json({ success: true, data: text, usage: { totalTokenCount: tokenUsage } });
|
|
|
|
| 126 |
});
|
| 127 |
|
| 128 |
const response = await bedrockClient.send(command);
|
| 129 |
+
|
| 130 |
+
// ONLY CHANGE THIS — everything else in /api/generate stays identical
|
| 131 |
+
|
| 132 |
+
// BEFORE — stops at first block, returns undefined if thinking block comes first
|
| 133 |
+
const text = response.output.message.content.find(b => b.text)?.text;
|
| 134 |
+
|
| 135 |
+
// AFTER — scans all blocks, concatenates every text block found, ignores reasoning blocks
|
| 136 |
+
const contentBlocks = response.output?.message?.content || [];
|
| 137 |
+
const text = contentBlocks
|
| 138 |
+
.filter(b => b.text)
|
| 139 |
+
.map(b => b.text)
|
| 140 |
+
.join("") || null;
|
| 141 |
+
|
| 142 |
+
if (!text) {
|
| 143 |
+
console.error(`[${model.toUpperCase()}] No text block returned. Block types:`,
|
| 144 |
+
JSON.stringify(contentBlocks.map(b => Object.keys(b))));
|
| 145 |
+
return res.status(500).json({ success: false, error: "Model returned no text content" });
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// const text = response.output.message.content.find(b => b.text)?.text;
|
| 149 |
const tokenUsage = response.usage ? (response.usage.inputTokens + response.usage.outputTokens) : 0;
|
| 150 |
|
| 151 |
res.json({ success: true, data: text, usage: { totalTokenCount: tokenUsage } });
|