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/

Like (0)
luotuoemo的头像luotuoemo
Previous 2023年11月6日 下午4:07
Next 2023年11月6日 下午4:50

相关推荐

  • CHATGPT在皮革制品设计中有哪些应用?

    在皮革制品设计中,CHATGPT可以有以下应用: 设计灵感:CHATGPT可以通过生成各种皮革制品的设计灵感,为设计师提供创意和想法。它可以提供不同风格、不同形状和不同用途的设计概念,帮助设计师拓宽思路和发展出独特的皮革制品设计。 材料选择:CHATGPT可以根据设计需求和要求,推荐适合特定皮革制品的材料。它可以根据设计师输入的要求,考虑皮革的质地、颜色、厚…

    2023年6月29日
    32800
  • 如何用chatgpt 批量做短视频

    要使用ChatGPT进行批量短视频制作,可以按照以下步骤进行操作: 数据准备:准备好用于生成短视频的文本数据。可以是一组问题和对应的回答,或者是一组对话的文本。 安装ChatGPT API:在你的开发环境中安装ChatGPT API。可以参考OpenAI官方文档进行安装和设置。 编写代码:使用你喜欢的编程语言,编写代码来连接到ChatGPT API并进行批量…

    2023年9月27日
    30400
  • 如何用chatgpt做视频

    要使用ChatGPT制作视频,您可以按照以下步骤操作: 准备数据:收集与您想要制作视频的主题相关的文本数据。这些数据可以是对话、剧本、字幕或其他任何与视频内容相关的文本。 模型训练:使用文本数据来训练ChatGPT模型。您可以使用GPT-3.5-turbo模型进行训练,具体训练步骤可以参考OpenAI的文档。 视频生成:一旦您的模型训练完成,您可以使用已训练…

    2023年8月24日
    29600
  • chatgpt电脑版下载与安装

    要下载和安装ChatGPT的电脑版,您可以按照以下步骤进行操作: 前往OpenAI官方网站,并登录您的账户。如果没有账户,您需要先注册一个。 导航到OpenAI的产品页面,找到ChatGPT并点击进入该页面。 在ChatGPT页面上,您会看到关于该模型的描述和信息。请确保您阅读了相应的文档和说明。 在页面上找到”Request Access&#8…

    2023年12月2日
    30900
  • chatgptplus

    ChatGPTPlus is a service offered by OpenAI that provides an enhanced version of the ChatGPT (Generative Pre-trained Transformer) model. It offers more advanced conversational capab…

    2023年11月22日
    29900

发表回复

Please Login to Comment

联系我们

4000-747-360

在线咨询: QQ交谈

邮件:582059487@qq.com

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

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