Apprenez le français avec un professeur d'IA
<input type="text" id="user-input" placeholder="Введите сообщение...">
<button id="send-btn">Отправить</button>
[removed]
document.addEventListener('DOMContentLoaded', function () {
const chatBox = document.getElementById('chat-box');
const userInput = document.getElementById('user-input');
const sendBtn = document.getElementById('send-btn');
async function sendMessage(message) {
chatBox[removed] += `
chatBox.scrollTop = chatBox.scrollHeight;
try {
const response = await fetch('https://api.openai.com/v1/engines/davinci-codex/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `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` // Замените YOUR_API_KEY на ваш реальный API-ключ OpenAI.
},
body: JSON.stringify({
prompt: message,
max_tokens: 100
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
const botMessage = data.choices[0].text.trim();
chatBox[removed] += `
chatBox.scrollTop = chatBox.scrollHeight;
} catch (error) {
console.error('Ошибка:', error);
chatBox[removed] += `
}
}
sendBtn.addEventListener('click', () => {
const message = userInput.value;
if (message.trim() === '') return;
userInput.value = '';
sendMessage(message);
});
});
[removed]
Write a public review