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's avatarluotuoemo
上一篇 2023年11月6日 下午4:07
下一篇 2023年11月6日 下午4:50

相关推荐

  • chatgpt对教育和社会的影响

    ChatGPT对教育和社会有广泛的影响。以下是一些主要方面: 教育资源和学习支持:ChatGPT可以为学生提供学习资源和支持。它可以回答问题、提供解释、提供例子等,帮助学生理解和掌握学习内容。此外,ChatGPT还可以为教师提供教学资源和工具,帮助他们更好地教授学生。 个性化学习:ChatGPT可以根据学生的个体需求和学习风格提供个性化的学习体验。它可以根据…

    2023年8月5日
    67100
  • chat 网站

    有很多聊天网站可以选择,以下是一些常见的聊天网站: Omegle:这是一个随机聊天网站,你可以与陌生人进行匿名聊天。 Chatroulette:这也是一个随机聊天网站,但与Omegle不同,它提供视频聊天功能。 Discord:主要用于游戏社区的聊天平台,可以创建私人聊天室和群组,支持文字聊天、语音聊天和视频聊天。 WhatsApp:这是一个流行的手机聊天应…

    2023年11月28日
    82500
  • CHATGPT如何提高化学实验数据分析效果?

    以下是提高化学实验数据分析效果的一些建议: 精确记录数据:确保在实验过程中精确记录数据,包括实验条件、仪器测量值和实验结果等。在记录数据时,应尽量避免出现错误或者遗漏。 重复实验:进行多次实验以获得更加准确和可靠的结果。在实验中,应尽可能地控制变量,确保实验条件尽量一致。 数据处理:对实验数据进行处理,包括数据清洗、数据转换和数据分析等。数据清洗包括消除异常…

    2023年6月24日
    79100
  • ChatGPT注册方法

    要注册ChatGPT,您需要访问OpenAI的网站并按照以下步骤进行注册: 访问OpenAI网站。 点击主页上的”Get started”或类似按钮。 创建一个OpenAI账号,提供所需的个人信息,例如您的电子邮件地址和密码。 完成账号验证步骤,可能需要通过电子邮件进行确认。 登录到您的OpenAI账号。 导航到OpenAI Dash…

    2023年7月20日
    85900
  • chatgpt为什么国内不能用

    chatgpt国内能用吗? ChatGPT国内是可以使用的,只需要去官网注册一个OpenAI帐号,然后使用第三方接码平台获取短信验证码,就可以成功注册帐号,注册成功之后国内就可以使用ChatGPT。ChatGPT是美国人工智能研究实验室OpenAI新推出的一种人工智能技术驱动的自然语言处理工具,使用了Transformer神经网络架构,也是GPT-3.5架构…

    2023年9月2日
    68000

发表回复

登录后才能评论

联系我们

4000-747-360

在线咨询: QQ交谈

邮件:582059487@qq.com

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

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