Pepguy commited on
Commit
fc9d15a
Β·
verified Β·
1 Parent(s): 3017841

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +43 -14
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
- const body = {
1797
- anthropic_version: "bedrock-2023-05-31",
1798
- max_tokens: 10000,
1799
- messages: [{ role: "user", content: prompt }],
1800
- temperature: 0.9,
1801
- //top_p: 0.95,
1802
- };
1803
- const cmd = new InvokeModelCommand({
1804
- modelId: BEDROCK_MODEL,
1805
- body: JSON.stringify(body),
1806
- contentType: "application/json",
1807
- accept: "application/json",
1808
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1809
  const t0 = Date.now();
1810
- const res = await bedrock.send(cmd);
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`);