const chatForm = document.querySelector('#chat-form');
const chatInput = document.querySelector('#chat-input');
const chatList = document.querySelector('#chat-list');
// create a new instance of OpenAI's GPT
const gpt = new OpenAI('YOUR_API_KEY');
// function to add a new chat message to the list
function addMessage(message, sender) {
const li = document.createElement('li');
li.textContent = `${sender}: ${message}`;
chatList.appendChild(li);
}
// function to send a user message to the GPT and add the response to the chat list
async function sendMessage(event) {
event.preventDefault();
const message = chatInput.value;
addMessage(message, 'You');
chatInput.value = '';
const response = await gpt.complete({
engine: 'davinci',
prompt: `User: ${message}\nAI:`,
maxTokens: 100,
n: 1,
stop: '\n'
});
addMessage(response.choices[0].text.trim(), 'AI');
}
// add an event listener to the chat form to send messages when the form is submitted
chatForm.addEventListener('submit', sendMessage);
header {
text-align: center;
margin-top: 20px;
}
#chat-container {
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
margin-top: 20px;
}
#chat-list {
list-style: none;
padding: 0;
margin: 0;
height: 300px;
overflow-y: scroll;
}
#chat-form {
display: flex;
align-items: center;
margin-top: 10
الحصول على الرابط
Facebook
X
Pinterest
بريد إلكتروني
التطبيقات الأخرى
تعليقات
المشاركات الشائعة من هذه المدونة
مباريات اليوم أفضل مباريات اليوم الفريق المضيف الفريق الضيف التوقيت الدوري جارٍ تحميل المباريات...
تعليقات
إرسال تعليق