我让chat gpt以gpt 3为模型写一个聊天机器人代码,他真的写了。
网站已创建,但无法发送邮件。
我还得到了一个gpt API密钥并使用了它,但它似乎工作得不好。有什么问题吗?
下面是gpt编写的代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ChatGPT Demo</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="chat-window">
<div class="chat-header">
<h1>ChatGPT</h1>
</div>
<div class="chat-body">
<ul class="message-list">
<li class="message bot">
<p>Hello! How can I help you today?</p>
</li>
</ul>
</div>
<div class="chat-footer">
<input id="input" type="text" placeholder="Type your message here...">
<button onclick="send()">Send</button>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@openai/api"></script>
<script>
// OpenAI API Key 설정
const openai = window.openai;
const api_key = 'YOUR_API_KEY';
const model_engine = 'davinci';
// API 호출하여 응답 받기
const askGPT3 = async (input) => {
console.log(input); // This is getting logged but below API is not being called.
const response = await openai.Completion.create({
engine: model_engine,
prompt: input,
max_tokens: 1024,
n: 1,
stop: null,
temperature: 0.5,
apiKey: api_key
});
return response.choices[0].text.trim();
};
// 대화 시작
const startConversation = async () => {
const botMessage = document.querySelector('.message.bot p');
const answer = await askGPT3('Hello!');
botMessage.innerHTML = answer;
};
startConversation();
// 대화 전송
const send = async () => {
const input = document.getElementById('input').value;
const messageList = document.querySelector('.message-list');
const userMessage = `<li class="message user"><p>${input}</p></li>`;
messageList.insertAdjacentHTML('beforeend', userMessage);
const botMessage = `<li class="message bot"><p>${await askGPT3(input)}</p></li>`;
messageList.insertAdjacentHTML('beforeend', botMessage);
document.getElementById('input').value = '';
};
// 대화 엔터키 전송
const input = document.getElementById('input');
input.addEventListener('keyup', (event) => {
if (event.keyCode === 13) {
event.preventDefault();
document.querySelector('button').click();
}
});
</script>
</body>
</html>
我点击send发送消息,但它不工作-消息没有发送到API。
1条答案
按热度按时间wfveoks01#
跟我打的一模一样试着说确切的代码然后“不工作”或再次询问,然后说它不工作,如果它提供相同的代码。