Hello, I’ve just started working with the OpenAI API. Initially, when I connected to the API, it gave me nonsense and random responses. After researching, I found out about the ‘temperature’ setting. I adjusted the temperature, but it didn’t help much.
Then, when I tried to use the assistant replace the davinci with assistant ID
it said ‘Unauthorized’." what I’m missing, I’m new to this space just couple hours. Soo any help will apperciated. Thanks.
<script>
const chatBox = document.getElementById("chat-box");
const userInput = document.getElementById("user-input");
function addMessage(message, isUser = false) {
const msgElement = document.createElement("div");
msgElement.textContent = message;
if (isUser) {
msgElement.style.textAlign = "right";
}
chatBox.appendChild(msgElement);
chatBox.scrollTop = chatBox.scrollHeight;
}
userInput.addEventListener("keyup", function (event) {
if (event.key === "Enter") {
const userMessage = userInput.value;
addMessage("You: " + userMessage, true);
userInput.value = "";
fetch("https://api.openai.com/v1/engines/asst_yKa.........../completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer sk-V.................3311WWDoc" ,
},
body: JSON.stringify({
prompt: userMessage,
max_tokens: 50,
temperature: 1
}),
})
.then(response => response.json())
.then(data => {
if (data.choices && data.choices.length > 0) {
const rabbit_response = data.choices[0].text;
addMessage("Rabbit: " + rabbit_response);
} else {
console.error("Check Choice");
}
})
.catch(error => {
console.error("There is a connection problem: " + error);
});
}
});
</script>