Skip to content

Commit 0249ab8

Browse files
authored
Use anthropic-dangerous-direct-browser-access: true
Now talks to the Anthropic API directly using their new anthropic-dangerous-direct-browser-access: true header. Also shows a "Generating..." message. Code change mostly by Claude: https://gist.github.com/simonw/6ff7bc0d47575a53463abc3482608f74
1 parent f750275 commit 0249ab8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

haiku.html

+24-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
max-height: 80%;
3737
overflow: auto;
3838
}
39+
#generating {
40+
position: absolute;
41+
top: 50%;
42+
left: 50%;
43+
transform: translate(-50%, -50%);
44+
color: white;
45+
background-color: rgba(0, 0, 0, 0.7);
46+
padding: 10px;
47+
border-radius: 5px;
48+
display: none;
49+
font-family:'Courier New', Courier, monospace;
50+
}
3951
</style>
4052
</head>
4153
<body>
@@ -87,6 +99,7 @@
8799
</button>
88100
</div>
89101
<pre id="response"></pre>
102+
<div id="generating">Generating...</div>
90103
<script>
91104
const video = document.getElementById("video");
92105
video.setAttribute("autoplay", "");
@@ -96,6 +109,7 @@
96109
const captureBtn = document.getElementById("captureBtn");
97110
switchCameraBtn.style.display = "none";
98111
const responseElement = document.getElementById("response");
112+
const generatingElement = document.getElementById("generating");
99113
let currentStream;
100114
let currentCamera = "front";
101115

@@ -181,12 +195,17 @@
181195
},
182196
],
183197
};
184-
fetch("https://anthropic-proxy.vercel.app/v1/messages", {
198+
199+
// Show "Generating..." message
200+
generatingElement.style.display = "block";
201+
202+
fetch("https://api.anthropic.com/v1/messages", {
185203
method: "POST",
186204
headers: {
187205
"x-api-key": apiKey,
188206
"anthropic-version": "2023-06-01",
189207
"content-type": "application/json",
208+
"anthropic-dangerous-direct-browser-access": "true"
190209
},
191210
body: JSON.stringify(requestBody),
192211
})
@@ -198,6 +217,10 @@
198217
})
199218
.catch((error) => {
200219
console.error("Error sending image to the Anthropic API:", error);
220+
})
221+
.finally(() => {
222+
// Hide "Generating..." message
223+
generatingElement.style.display = "none";
201224
});
202225
});
203226
// Start the camera when the page loads

0 commit comments

Comments
 (0)