Dear Forum and Convai Team,
Apologies if the solution is something obvious; not an expert coder here (or really a developer at all…), and could not find a similar topic.
The background:
Perhaps not the exact intended use, but just using Convai because it offers a nice way to customize/specialize the AI and its responses. Trying to build a frontend web application using javascript/html/css in which users can ask questions about the ocean to an ‘ocean expert’ AI. I first tested out the interaction API in Python (because I’m more familiar with Python), and got the AI to respond using requests, and it looked like it indeed fits my purposes quite well.
I have now tried to build a simple webpage, which I’m testing using the VScode “Live server” extension. I’m using JS fetch to call the interaction API.
The problem:
Anytime I call for a response, the preflight goes out alright, but then I get Status Code 500 from the fetch. From the network tab: ({“ERROR”: “Failed to get response. Please reach out at [support@convai.com]”, “Reference ID”: “770089af-3489-4db6-b17d-3209a2188263”}).
Here is the part of the code responsible for the fetch:
if (!promptInput.value) {
addMessage(“Husk at stille et spørgsmål.”, “Dora”);
return;
}
try {
//Specify the request made to the convai API
const payload = {
userText: promptInput.value,
charID: charID,
sessionID: sessionID,
voiceResponse: ‘False’
};
//Make the request
const response = await fetch(API_URL, {
method: “POST”,
headers: headers,
body: JSON.stringify(payload)
});
;
//Store the response
const data = await response.json();
//Access the text response
const characterResponse = data.text;
//Update the session ID to retain context
sessionID = data.sessionID;
Where:
API_URL = https://api.convai.com/character/getResponse
sessionID = -1 (until the first fetch has gone through)
headers = {‘CONVAI-API-KEY’: ‘my-api-key’}
charID = ‘my-char-id’
and promptInput comes from a text field (the loop is ended in the start if there’s no value)
And in case you want to have a look, here the information from the fetch request:
GetResponse copied as HAR.txt (10.6 KB)