Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
runas24 authored Apr 20, 2024
1 parent 8ab49c9 commit 668440c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ function sendMessage() {
const userMessage = userInput.value;
userInput.value = '';
appendMessage(userMessage, 'You');
fetch('/sendMessage', {

// Отправка запроса к API GPT
fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-32323-29SWBUEQyj1Jx9346eG4T3BlbkFJOXxLTCXjZCoQlOQvrxVZ', // Замените на свой ключ API GPT
},
body: JSON.stringify({ message: userMessage })
body: JSON.stringify({
prompt: userMessage,
model: 'text-davinci-003', // Здесь можно указать нужную модель GPT
max_tokens: 50 // Максимальное количество токенов в ответе
})
})
.then(response => response.json())
.then(data => {
appendMessage(data.message, 'Bot');
displayBotResponse(data.message); // Отображаем ответ бота
const botMessage = data.choices[0].text.trim();
appendMessage(botMessage, 'Bot');
displayBotResponse(botMessage); // Отображаем ответ бота
})
.catch(error => console.error('Error:', error));
}

0 comments on commit 668440c

Please sign in to comment.