chatgpt聊天界面 html

下面是一个简单的ChatGPT聊天界面的HTML示例:

<!DOCTYPE html>
<html>
<head>
    <title>ChatGPT 聊天界面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f2f2f2;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #ffffff;
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
        }

        .chat-log {
            height: 400px;
            overflow-y: scroll;
            padding: 10px;
            border: 1px solid #ccc;
        }

        .user-message, .bot-message {
            margin-bottom: 10px;
            padding: 10px;
            border-radius: 5px;
        }

        .user-message {
            background-color: #dcf8c6;
        }

        .bot-message {
            background-color: #f6f6f6;
        }

        .input-container {
            margin-top: 20px;
        }

        input[type="text"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 16px;
        }

        button {
            margin-top: 10px;
            padding: 10px 20px;
            background-color: #4caf50;
            color: #ffffff;
            border: none;
            border-radius: 5px;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="chat-log" id="chat-log"></div>
        <div class="input-container">
            <input type="text" id="user-input">
            <button onclick="sendMessage()">发送</button>
        </div>
    </div>

    <script>
        const chatLog = document.getElementById('chat-log');
        const userInput = document.getElementById('user-input');

        function sendMessage() {
            const message = userInput.value;

            if (message.trim() !== '') {
                appendUserMessage(message);
                userInput.value = '';
                scrollToBottom();
                getBotResponse(message);
            }
        }

        function appendUserMessage(message) {
            const userMessageElement = document.createElement('div');
            userMessageElement.classList.add('user-message');
            userMessageElement.textContent = message;
            chatLog.appendChild(userMessageElement);
        }

        function appendBotMessage(message) {
            const botMessageElement = document.createElement('div');
            botMessageElement.classList.add('bot-message');
            botMessageElement.textContent = message;
            chatLog.appendChild(botMessageElement);
        }

        function scrollToBottom() {
            chatLog.scrollTop = chatLog.scrollHeight;
        }

        function getBotResponse(userMessage) {
            // 在这里添加与ChatGPT的API交互代码,获取机器人的回复
            // 然后调用appendBotMessage函数将回复添加到聊天界面中
        }
    </script>
</body>
</html>

这个HTML文件包含一个简单的聊天界面,具有一个聊天记录框(chat-log)、一个用户输入框(user-input)和一个发送按钮。用户在输入框中输入消息,并点击发送按钮,就会调用sendMessage()函数发送消息,并将用户的消息显示在聊天记录框中。在getBotResponse()函数中,你可以添加与ChatGPT的API交互代码,获取机器人的回复,并将回复添加到聊天记录框中。

<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatGPT Chat Interface</title>
<style>
    body {
        background-color: #f0f0f0;
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
    }

    .container {
        display: flex;
        flex-direction: column;
        height: 100vh;
    }

    .header {
        background-color: #333;
        color: white;
        padding: 20px;
    }

    .header h1 {
        margin: 0;
    }

    .chatbox {
        flex: 1;
        padding: 20px;
        overflow-y: scroll;
        scrollbar-width: thin;
        scrollbar-color: #ccc #f0f0f0;
    }

    .chatbox::-webkit-scrollbar {
        width: 8px;
    }

    .chatbox::-webkit-scrollbar-track {
        background: #f0f0f0;
    }

    .chatbox::-webkit-scrollbar-thumb {
        background-color: #ccc;
        border-radius: 4px;
    }

    .input-area {
        display: flex;
        align-items: center;
        padding: 20px;
        background-color: #f0f0f0;
    }

    .input-area input {
        flex: 1;
        height: 40px;
        padding: 10px;
        border: none;
        border-radius: 4px;
    }

    .input-area button {
        height: 40px;
        margin-left: 10px;
        padding: 0 20px;
        background-color: #333;
        color: white;
        border: none;
        border-radius: 4px;
        cursor: pointer;
    }
</style>

</head>

<body>

<div class="container">
    <div class="header">
        <h1>ChatGPT Chat Interface</h1>
    </div>
    <div class="chatbox" id="chatbox">
        <!-- Chat messages will be dynamically added here -->
    </div>
    <div class="input-area">
        <input type="text" id="userInput" placeholder="Type your message...">
        <button id="sendButton">Send</button>
    </div>
</div>

<script>
    const chatbox = document.getElementById('chatbox');
    const userInput = document.getElementById('userInput');
    const sendButton = document.getElementById('sendButton');

    // Function to add user message to chatbox
    function addUserMessage(message) {
        const userMessage = document.createElement('div');
        userMessage.className = 'message user';
        userMessage.textContent = message;
        chatbox.appendChild(userMessage);
    }

    // Function to add assistant message to chatbox
    function addAssistantMessage(message) {
        const assistantMessage = document.createElement('div');
        assistantMessage.className = 'message assistant';
        assistantMessage.textContent = message;
        chatbox.appendChild(assistantMessage);
    }

    // Function to handle user input
    function handleUserInput() {
        const message = userInput.value;
        addUserMessage(message);
        // TODO: Send user message to backend for processing and get assistant's response
        // Replace the following line with appropriate code to handle backend communication
        const assistantResponse = "Assistant's response goes here";
        addAssistantMessage(assistantResponse);
        userInput.value = '';
    }

    // Event listener for send button click
    sendButton.addEventListener('click', handleUserInput);

    // Event listener for Enter key press
    userInput.addEventListener('keydown', function (event) {
        if (event.key === 'Enter') {
            handleUserInput();
        }
    });
</script>

</body>

</html>

chatgpt聊天界面 html 发布者:luotuoemo,转转请注明出处:https://www.chatairc.com/34216/

(0)
luotuoemo的头像luotuoemo
上一篇 2023年11月6日 下午4:07
下一篇 2023年11月6日 下午4:50

相关推荐

  • CHATGPT如何提高社会学研究效果?

    为了提高CHATGPT的社会学研究效果,可以采取以下措施: 1.加强社会学理论知识的学习和积累。 CHATGPT需要建立在扎实的社会学理论基础上,才能进行深入的研究和分析。因此,学习和积累社会学理论知识是非常重要的。 2.增加社会学研究的数据来源。 CHATGPT可以通过收集更多的数据来提高社会学研究效果。可以利用各种渠道收集数据,如调查问卷、访谈、观察等,…

    2023年6月25日
    23400
  • chatgpt扩展应用场景

    ChatGPT的扩展应用场景可以包括以下几个方面: 在线客服和智能助手:ChatGPT可以作为在线客服系统的一部分,帮助用户解答常见问题、提供产品和服务信息,并进行基本的问题解决。它可以与用户进行即时对话,并提供个性化的建议和答案。 语音助手和智能音箱:ChatGPT可以与语音识别技术结合,用于开发智能音箱和语音助手。用户可以通过语音进行对话,并得到符合语境…

    2023年10月1日
    20000
  • 如何使用chatgpt

    要使用ChatGPT,您可以按照以下步骤操作: 登录OpenAI网站:访问OpenAI网站并登录您的账户。 使用ChatGPT页面:在OpenAI的控制台上,找到ChatGPT页面并点击进入。 创建一个对话:在ChatGPT页面上,您可以创建一个对话与模型进行交流。在对话框中输入对话的开始部分,例如:”用户:您好!”。 与模型进行交互…

    2023年8月1日
    22300
  • 人工文案编写ai

    人工文案编写AI(Artificial Intelligence)是一种使用人工智能技术进行文案创作的工具。它可以基于大量的语言数据和创意模型,自动生成符合特定需求的文案内容。 人工文案编写AI通常利用自然语言处理、机器学习和深度学习等技术,通过对海量文本数据进行学习和分析,从而学习到文案的写作风格、语法规则和内容结构等特征。用户可以通过提供一些关键词、简要…

    2023年12月20日
    20700
  • ChatGPT入门教程 详解人工智能

    ChatGPT是一种基于人工智能技术的聊天机器人模型,它能够模拟人类对话行为并回答用户的问题。以下是一个简单的ChatGPT入门教程,帮助你了解如何使用ChatGPT构建一个简单的聊天机器人。 步骤1:安装必要的库首先,你需要安装OpenAI的Python库,可以使用以下命令: pip install openai 步骤2:导入所需库在你的Python代码中…

    2023年9月27日
    23500

发表回复

登录后才能评论

联系我们

4000-747-360

在线咨询: QQ交谈

邮件:582059487@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
国内Chat Ai版本直接使用:https://chat.chatairc.com/