An AI movie by Interceptor Films
The Rat King
Talk to the Map Maker
// create a stream on the server
let response = await fetch("https://api.gooey.ai/v3/integrations/stream/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
// your integration's ID as shown in the Gooey.AI Integrations tab
"integration_id": "j9D",
// the input text for the bot
"input_text": "Hello, world!",
}),
});
// get the server-sent events URL
let sseUrl = response.headers.get("Location");
console.log(sseUrl);
// clear screen
document.body.innerHTML = "";
// start listening to the stream
const evtSource = new EventSource(sseUrl);
// handle the stream events
evtSource.onmessage = (event) => {
// display the message in the browser
document.body.innerHTML += event.data + "<br><br>";
// parse the message as JSON
let data = JSON.parse(event.data);
// log the message to the console
console.log(data.type, data);
// check if the message is the final response
if (data.type === "final_response") {
// close the stream
evtSource.close();
}
};
evtSource.onerror = (event) => {
// log the error to the console
console.error(event.data);
// close the stream
evtSource.close();
}