Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -39,6 +39,8 @@ import {
|
|
| 39 |
BedrockRuntimeClient,
|
| 40 |
InvokeModelCommand
|
| 41 |
} from "@aws-sdk/client-bedrock-runtime";
|
|
|
|
|
|
|
| 42 |
|
| 43 |
// ββ CONFIG ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 44 |
const PORT = parseInt(process.env.PORT || "7860");
|
|
@@ -1793,21 +1795,48 @@ OUTPUT THE JSON ARRAY NOW:`;
|
|
| 1793 |
}
|
| 1794 |
|
| 1795 |
async function callBedrock(prompt) {
|
| 1796 |
-
|
| 1797 |
-
|
| 1798 |
-
|
| 1799 |
-
|
| 1800 |
-
|
| 1801 |
-
|
| 1802 |
-
|
| 1803 |
-
|
| 1804 |
-
|
| 1805 |
-
|
| 1806 |
-
|
| 1807 |
-
|
| 1808 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1809 |
const t0 = Date.now();
|
| 1810 |
-
const res =
|
| 1811 |
const raw = JSON.parse(Buffer.from(res.body).toString("utf8"));
|
| 1812 |
const text = raw.content[0].text;
|
| 1813 |
log(`Bedrock call ${((Date.now()-t0)/1000).toFixed(1)}s β ${text.length} chars`);
|
|
|
|
| 39 |
BedrockRuntimeClient,
|
| 40 |
InvokeModelCommand
|
| 41 |
} from "@aws-sdk/client-bedrock-runtime";
|
| 42 |
+
import { NodeHttpHandler } from "@smithy/node-http-handler";
|
| 43 |
+
|
| 44 |
|
| 45 |
// ββ CONFIG ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 46 |
const PORT = parseInt(process.env.PORT || "7860");
|
|
|
|
| 1795 |
}
|
| 1796 |
|
| 1797 |
async function callBedrock(prompt) {
|
| 1798 |
+
const bedrockClient = new BedrockRuntimeClient({
|
| 1799 |
+
region: "us-east-1",
|
| 1800 |
+
requestHandler: new NodeHttpHandler({
|
| 1801 |
+
http2Handler: undefined,
|
| 1802 |
+
})
|
| 1803 |
+
});
|
| 1804 |
+
|
| 1805 |
+
const command = new ConverseCommand({
|
| 1806 |
+
modelId: BEDROCK_MODEL,
|
| 1807 |
+
system:[{ text: prompt }],
|
| 1808 |
+
messages: [{ role: "user", content: {text: "OUTPUT THE JSON ARRAY NOW"} }],
|
| 1809 |
+
|
| 1810 |
+
// Ensure maxTokens is large enough for reasoning + response
|
| 1811 |
+
inferenceConfig: {
|
| 1812 |
+
maxTokens: 4000,
|
| 1813 |
+
temperature: 1
|
| 1814 |
+
},
|
| 1815 |
+
|
| 1816 |
+
additionalModelRequestFields: (
|
| 1817 |
+
/* if (model.includes("haiku")) {
|
| 1818 |
+
return {
|
| 1819 |
+
reasoning_config: {
|
| 1820 |
+
type: "enabled",
|
| 1821 |
+
budget_tokens: 2048
|
| 1822 |
+
}
|
| 1823 |
+
};
|
| 1824 |
+
} */
|
| 1825 |
+
|
| 1826 |
+
// thinking: { type: "adaptive" },
|
| 1827 |
+
output_config: { effort: "high" }
|
| 1828 |
+
)
|
| 1829 |
+
|
| 1830 |
+
|
| 1831 |
+
|
| 1832 |
+
});
|
| 1833 |
+
|
| 1834 |
+
const response = await bedrockClient.send(command);
|
| 1835 |
+
|
| 1836 |
+
|
| 1837 |
+
|
| 1838 |
const t0 = Date.now();
|
| 1839 |
+
const res = response;
|
| 1840 |
const raw = JSON.parse(Buffer.from(res.body).toString("utf8"));
|
| 1841 |
const text = raw.content[0].text;
|
| 1842 |
log(`Bedrock call ${((Date.now()-t0)/1000).toFixed(1)}s β ${text.length} chars`);
|