Code Monkey home page Code Monkey logo

chatgpt-html's Introduction

chatgpt-html

使用acheong08的官方ChatGPT接口,实现简单HTML网页版在线聊天

该版本基于ChatGPT开发,想使用OPENAI API KEY的请访问chatgpt-web

项目由来及一些说明

  • 想在html实现人人可访问的ChatGPT网页应用
  • ChatGPT本身支持上下文关联,但个人技术菜鸡,无法在html编写连续对话
  • ChatGPT的回复内容比OPENAI API KEY更自然,特别是面对复杂表达或场景时,下图为例 S{_0)XRVDB(3)SKFR$4P7VV

部署

获取OpenAI API KEY

配置

使用Docker Compose

以下文件放同一目录

  • 新建.env文件,粘贴以下代码并保存
OPENAI_API_KEY="前面获取到的OpenAI API KEY"
  • 新建chat.html网页文件,粘贴以下代码并保存(UI很丑,建议各自美化)
<!DOCTYPE html>
<html lang="en">

<!--自适应屏幕大小-->
<meta name="viewport" content="width=device-width,initial-scale=1" />

<head>
    <!-- <link rel="shortcut icon" href="" type="image/x-icon" /> -->
    <meta charset="UTF-8">
    <title>ChatGPT</title>
    <style>
      body {
        color: #333;
        background-color: #eee;
      }
    @media (prefers-color-scheme: dark) {
      body {
        background: black;
        color: white;
      }
    }
    </style>
</head>

<body>
    <div align="center">
        <h2>ChatGPT</h2>
        <div>注意:接口返回可能比较慢(服务在国外,并且ChatGPT返回速度也比较慢),提交后需要等待处理完成,请勿重复提交!!!</div>
        <div>~接口返回有长度限制~</div>
        <hr />
        {% if message %} {{ message }} {% endif %}
        <form method="post" onsubmit="submit.disabled=true">
            <textarea style="width:35%;" name="question" placeholder="点击这里输入问题" rows="11" id="form"></textarea>
            <br>
            <input type="submit" style="width:150px;height:50px;background-color:green;font-size:30px" value="提交" id="submit" />
        </form>
        <div id="loading" style="display:none; color:red"><b>后端正在处理,请稍等...</b></div>
        {% if question %}
        <div style="text-align: left"><b>人类:</b>
            <pre id="question">{{ question }}</pre>
        </div>
        <hr />
        <div style="text-align: left"><b>人工智障:</b>
            <pre style="text-align:left; white-space: pre-wrap;" id="res">{{ res }}</pre>
        </div>
        {% endif %}
    </div>
</body>
<script>
    let loading = document.getElementById('loading');
    let form = document.querySelector('form');
    form.addEventListener('submit', () => {
        loading.style.display = 'block';
    });
</script>
</html>
  • 新建docker-compose.yml配置文件,粘贴以下内容并保存
version: '3'
services:
  chatgpt:
    image: sheepgreen/chatgpt-html:api #如果是arm,请换成chatgpt-html:apiarm
    container_name: htmchat
    volumes:
      - ./.env:/home/appuser/.env
      - ./chat.html:/home/appuser/templates/chat.html
    ports:
      - "9999:80" #80为容器内部端口,9999为外部映射端口,可自行更改
    restart: always
  • 输入docker-compose up -d即启动成功

注意事项

  • 访问地址为http://ip:port
  • 修改chat.html文件后,需要docker restart htmchat才能生效

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.