-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathopenai.js
More file actions
42 lines (37 loc) · 997 Bytes
/
openai.js
File metadata and controls
42 lines (37 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import OpenAI from "openai";
import dotenv from "dotenv";
dotenv.config();
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
export async function sendCUARequest({
messages = [],
screenshotBase64,
previousResponseId,
callId,
pendingSafetyChecks = [],
}) {
const input = [...messages];
// If responding to a computer_call, attach a screenshot along with any safety checks
if (callId && screenshotBase64) {
const outputItem = {
type: "computer_call_output",
call_id: callId,
output: {
type: "computer_screenshot",
image_url: `data:image/png;base64,${screenshotBase64}`,
},
};
if (pendingSafetyChecks.length > 0) {
outputItem.acknowledged_safety_checks = pendingSafetyChecks;
}
input.push(outputItem);
}
return openai.responses.create({
model: "gpt-5.4",
previous_response_id: previousResponseId || undefined,
tools: [{ type: "computer" }],
input,
store: true,
});
}