Hello, I have made a chat function on a webpage. This works perfect with the standard model: gpt-4 works also with gpt-3.5-turbo.
The client has made her own model: Decoration-Color-Visualizer.
But when I change the value in the javascript it gives an error.
function sendMessageToOpenAI(message) {
const apiKey = ‘sk-YgAblablabla’;
const url = ‘https : // api. openai. com/ v1/ chat/ completions’;
const data = {
model: 'gpt-4', // Je kunt hier ook 'gpt-3.5-turbo' of Decoration-Color-Visualizer
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: message }
],
max_tokens: 150,
temperature: 0.7
};
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP Error: ${response.status}`);
}
return response.json();
})
.then(responseData => {
const assistantMessage = responseData.choices[0].message.content;
// Voeg het antwoord van de AI toe aan de chatbox
const assistantMessageElement = document.createElement('div');
assistantMessageElement.textContent = assistantMessage;
assistantMessageElement.className = 'assistant-message';
document.getElementById('chat-box').appendChild(assistantMessageElement);
document.getElementById('chat-box').scrollTop = document.getElementById('chat-box').scrollHeight;
})
.catch(error => {
console.error('Error:', error);
const errorMessageElement = document.createElement('div');
errorMessageElement.textContent = `Error: ${error.message}`;
errorMessageElement.className = 'error-message';
document.getElementById('chat-box').appendChild(errorMessageElement);
document.getElementById('chat-box').scrollTop = document.getElementById('chat-box').scrollHeight;
});
}
Could somebody help me, with some tips?
Thanks in advance.
Brian