Pepguy commited on
Commit
d3909f1
·
verified ·
1 Parent(s): 070eb04

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +58 -37
app.js CHANGED
@@ -12,23 +12,21 @@ const PORT = 7860;
12
  app.use(express.json());
13
 
14
  // --- 1. LOAD SYSTEM PROMPTS ---
15
- // Ensure prompts.json exists in the same directory
16
- // const prompts = JSON.parse(fs.readFileSync('./prompts.json', 'utf8'));
17
  const SYSTEM_PROMPT_PRO = "You are a pro";
18
  const SYSTEM_PROMPT_WORKER = "You are a worker";
19
 
20
  // --- 2. CLIENT INITIALIZATION ---
21
 
22
  /*
23
- # AWS BEDROCK CONFIG
24
- AWS_REGION=us-east-1
25
- AWS_ACCESS_KEY_ID=BedrockAPIKey-9pju-at-106774395747
26
- AWS_SECRET_ACCESS_KEY=ABSKQmVkcm9ja0FQSUtleS05cGp1LWF0LTEwNjc3NDM5NTc0NzpMenR2ZGhtUUlrOW52K0hseDZaTVF6ZGxOaDJZaU5kc3NmeksxVGJidVQ0TlNLK3dVZGN5ZzlpYTJIaz0=
27
-
28
- # AZURE OPENAI CONFIG
29
- AZURE_OPENAI_ENDPOINT=https://hollowpad-resource.cognitiveservices.azure.com/openai/deployments/gpt-5-mini/chat/completions?api-version=2024-05-01-preview
30
- AZURE_OPENAI_API_KEY=7U3m9NRkE38ThSWTr92hMgQ4hDCUFI9MAnFNrCgRL7MhdvckfTXwJQQJ99CBACHYHv6XJ3w3AAAAACOGV22P
31
- AZURE_OPENAI_DEPLOYMENT=gpt-5-mini # Or whatever you named your Azure deployment
32
  */
33
 
34
  const bedrockClient = new BedrockRuntimeClient({
@@ -39,16 +37,30 @@ const bedrockClient = new BedrockRuntimeClient({
39
  }
40
  });
41
 
 
 
 
 
 
 
 
 
42
  const azureOpenAI = new OpenAI({
43
- baseURL: "https://hollowpad-resource.cognitiveservices.azure.com/openai/deployments/gpt-5-mini/chat/completions?api-version=2024-05-01-preview", // e.g. https://res.openai.azure.com/openai/v1/
44
- apiKey: "7U3m9NRkE38ThSWTr92hMgQ4hDCUFI9MAnFNrCgRL7MhdvckfTXwJQQJ99CBACHYHv6XJ3w3AAAAACOGV22P"
 
 
45
  });
46
 
47
  // --- 3. EXECUTION LOGIC ---
48
 
49
  async function callClaude(userPrompt) {
50
  const command = new ConverseCommand({
51
- modelId: "anthropic.claude-4-6-sonnet-v1:0",
 
 
 
 
52
  // Official System Slot
53
  system: [
54
  { text: SYSTEM_PROMPT_PRO }
@@ -61,36 +73,45 @@ async function callClaude(userPrompt) {
61
  ]
62
  }
63
  ],
64
- inferenceConfig: {
65
- maxTokens: 56069,
66
- temperature: 1.0
67
  },
68
- // Official reasoning/thinking parameters for Claude
69
  additionalModelRequestFields: {
70
- thinking: {
71
- type: "enabled",
72
- budget_tokens: 40000
73
  }
74
  }
75
  });
76
 
77
  const response = await bedrockClient.send(command);
78
- // Accessing the first content block text
79
- return response.output.message.content[0].text;
 
 
 
 
 
 
 
 
80
  }
81
 
82
  async function callGptMini(userPrompt) {
83
  const response = await azureOpenAI.chat.completions.create({
84
- model: process.env.AZURE_OPENAI_DEPLOYMENT || "gpt-5-mini",
85
  messages: [
86
- { role: "developer", content: SYSTEM_PROMPT_WORKER },
87
- { role: "user", content: userPrompt }
 
 
88
  ],
89
- // Official Reasoning Parameters
90
  reasoning_effort: "high",
91
  max_completion_tokens: 56069,
92
  store: true
93
- // Note: temperature is omitted as it is incompatible with reasoning_effort
94
  });
95
 
96
  return response.choices[0].message.content;
@@ -136,23 +157,23 @@ app.get('/', (req, res) => {
136
  <div class="box">
137
  <h1>Hollowpad Battle Arena</h1>
138
  <p>Reasoning: High | Max Tokens: 56,069</p>
139
-
140
  <select id="model">
141
  <option value="gpt-mini">GPT-5 Mini (Worker Prompt)</option>
142
- <option value="claude">Claude 4.6 Sonnet (Pro Prompt)</option>
143
  </select>
144
-
145
- <textarea id="prompt" placeholder="Paste a Roblox task here..."></textarea>
146
  <button id="runBtn" onclick="execute()">Run High Reasoning Test</button>
147
-
148
  <div id="output">Output will appear here...</div>
149
  </div>
150
 
151
  <script>
152
  async function execute() {
153
- const btn = document.getElementById('runBtn');
154
- const out = document.getElementById('output');
155
- const model = document.getElementById('model').value;
156
  const prompt = document.getElementById('prompt').value;
157
 
158
  btn.disabled = true;
@@ -178,4 +199,4 @@ app.get('/', (req, res) => {
178
  `);
179
  });
180
 
181
- app.listen(PORT, () => console.log(`Server started: http://localhost:${PORT}`));
 
12
  app.use(express.json());
13
 
14
  // --- 1. LOAD SYSTEM PROMPTS ---
 
 
15
  const SYSTEM_PROMPT_PRO = "You are a pro";
16
  const SYSTEM_PROMPT_WORKER = "You are a worker";
17
 
18
  // --- 2. CLIENT INITIALIZATION ---
19
 
20
  /*
21
+ # AWS BEDROCK CONFIG
22
+ AWS_REGION=us-east-1
23
+ AWS_ACCESS_KEY_ID=BedrockAPIKey-9pju-at-106774395747
24
+ AWS_SECRET_ACCESS_KEY=ABSKQmVkcm9ja0FQSUtleS05cGp1LWF0LTEwNjc3NDM5NTc0NzpMenR2ZGhtUUlrOW52K0hseDZaTVF6ZGxOaDJZaU5kc3NmeksxVGJidVQ0TlNLK3dVZGN5ZzlpYTJIaz0=
25
+
26
+ # AZURE OPENAI CONFIG
27
+ AZURE_OPENAI_ENDPOINT=https://hollowpad-resource.cognitiveservices.azure.com
28
+ AZURE_OPENAI_API_KEY=7U3m9NRkE38ThSWTr92hMgQ4hDCUFI9MAnFNrCgRL7MhdvckfTXwJQQJ99CBACHYHv6XJ3w3AAAAACOGV22P
29
+ AZURE_OPENAI_DEPLOYMENT=gpt-5-mini
30
  */
31
 
32
  const bedrockClient = new BedrockRuntimeClient({
 
37
  }
38
  });
39
 
40
+ // FIX 3 & 4: baseURL must be just the deployment base (no path, no query string).
41
+ // The SDK appends /chat/completions automatically.
42
+ // api-version is passed via defaultQuery.
43
+ // Azure requires the "api-key" header instead of "Authorization: Bearer".
44
+ const AZURE_API_KEY = "7U3m9NRkE38ThSWTr92hMgQ4hDCUFI9MAnFNrCgRL7MhdvckfTXwJQQJ99CBACHYHv6XJ3w3AAAAACOGV22P";
45
+ const AZURE_DEPLOYMENT = process.env.AZURE_OPENAI_DEPLOYMENT || "gpt-5-mini";
46
+ const AZURE_BASE_URL = `https://hollowpad-resource.cognitiveservices.azure.com/openai/deployments/${AZURE_DEPLOYMENT}`;
47
+
48
  const azureOpenAI = new OpenAI({
49
+ apiKey: AZURE_API_KEY,
50
+ baseURL: AZURE_BASE_URL,
51
+ defaultQuery: { "api-version": "2024-05-01-preview" },
52
+ defaultHeaders: { "api-key": AZURE_API_KEY }
53
  });
54
 
55
  // --- 3. EXECUTION LOGIC ---
56
 
57
  async function callClaude(userPrompt) {
58
  const command = new ConverseCommand({
59
+ // FIX 1: Use a valid Bedrock cross-region inference profile model ID.
60
+ // "anthropic.claude-4-6-sonnet-v1:0" does not exist.
61
+ // Claude 3.7 Sonnet is the latest model with native extended thinking support.
62
+ modelId: "us.anthropic.claude-3-7-sonnet-20250219-v1:0",
63
+
64
  // Official System Slot
65
  system: [
66
  { text: SYSTEM_PROMPT_PRO }
 
73
  ]
74
  }
75
  ],
76
+ inferenceConfig: {
77
+ maxTokens: 56069,
78
+ temperature: 1.0 // Must be 1.0 when thinking is enabled
79
  },
 
80
  additionalModelRequestFields: {
81
+ thinking: {
82
+ type: "enabled",
83
+ budget_tokens: 40000
84
  }
85
  }
86
  });
87
 
88
  const response = await bedrockClient.send(command);
89
+
90
+ // FIX 2: When thinking is enabled, the content array has TWO blocks:
91
+ // [0] => { reasoningContent: { reasoningText: { text, signature } } } ← thinking
92
+ // [1] => { text: "..." } ← actual reply
93
+ // Grabbing content[0].text would return undefined and crash.
94
+ // We must find the block that actually has a .text property.
95
+ const textBlock = response.output.message.content.find(
96
+ block => block.text !== undefined
97
+ );
98
+ return textBlock ? textBlock.text : "No text response was generated.";
99
  }
100
 
101
  async function callGptMini(userPrompt) {
102
  const response = await azureOpenAI.chat.completions.create({
103
+ model: AZURE_DEPLOYMENT,
104
  messages: [
105
+ // FIX 4 (cont): "developer" role is not supported in api-version 2024-05-01-preview.
106
+ // Use "system" for broad compatibility.
107
+ { role: "system", content: SYSTEM_PROMPT_WORKER },
108
+ { role: "user", content: userPrompt }
109
  ],
110
+ // Official Reasoning Parameters (requires an o-series or reasoning-capable deployment)
111
  reasoning_effort: "high",
112
  max_completion_tokens: 56069,
113
  store: true
114
+ // Note: temperature is intentionally omitted incompatible with reasoning_effort
115
  });
116
 
117
  return response.choices[0].message.content;
 
157
  <div class="box">
158
  <h1>Hollowpad Battle Arena</h1>
159
  <p>Reasoning: High | Max Tokens: 56,069</p>
160
+
161
  <select id="model">
162
  <option value="gpt-mini">GPT-5 Mini (Worker Prompt)</option>
163
+ <option value="claude">Claude 3.7 Sonnet (Pro Prompt)</option>
164
  </select>
165
+
166
+ <textarea id="prompt" placeholder="Paste a task here..."></textarea>
167
  <button id="runBtn" onclick="execute()">Run High Reasoning Test</button>
168
+
169
  <div id="output">Output will appear here...</div>
170
  </div>
171
 
172
  <script>
173
  async function execute() {
174
+ const btn = document.getElementById('runBtn');
175
+ const out = document.getElementById('output');
176
+ const model = document.getElementById('model').value;
177
  const prompt = document.getElementById('prompt').value;
178
 
179
  btn.disabled = true;
 
199
  `);
200
  });
201
 
202
+ app.listen(PORT, () => console.log(`Server started: http://localhost:${PORT}`));