跳到主要内容

如何使用PerfxCloud实现ChatGPT-clone的web应用

PerfXCloud免费账户申请

本项目使用澎峰云(PerfXCloud) www.perfxcloud.cn ,网站上有详细的说明文档。 快速开始 | PerfXCloud

PerfXCloud 的 API 接口兼容 OpenAI 的 ChatGPT,可以直接使用 OpenAI SDK 或者其他中间件来访问 PerfXCloud。这使得开发者从 ChatGPT 或者其他平台切换到 PerfXCloud 变得非常非常容易。

如何使用PerfxCloud来实现ChatGPT-clone的web应用?

实现过程

  1. 克隆chatgpt-clone代码

    git clone https://github.com/xtekky/chatgpt-clone

    1. 在Linux环境下配置chatgpt-clone项目的虚拟环境

      1. 进入chatgpt-clone项目根目录

        cd chatgpt-clone

      2. 创建虚拟环境

        python -m venv venv

      3. 激活虚拟环境

        source venv/bin/activate

      4. 安装chatgpt-clone项目的依赖包

        pip install -r requirements.txt

      目前,已经完成了chatgpt-clone项目的运行环境。

  2. 环境变量配置

    使用PerfxCloud实现ChatGPT-clone的web应用,需要对chatgpt-clone项目中的三个文件进行环境变量配置

    1. 打开chatgpt-clone/config.json

      如上图所示,图中左侧为chatgpt-clone项目中原始的config.json的内容,其中,红色方框处为我们需要修改的内容,修改结果如上图右侧蓝色方框处所示。

      {
      "site_config": {
      "host" : "0.0.0.0",
      "port" : 1338,
      "debug": true
      },
      "openai_key": "sk-xxx",

      "openai_api_base": "https://cloud.perfxlab.cn",
      "proxy": {
      "enable": false,
      "http": "127.0.0.1:7890",
      "https": "127.0.0.1:7890"
      }
      }
    2. 打开chatgpt-clone/server/config.py

      如上图所示,在models中加入PerfxCloud的适配信息。

      models = {
      'text-gpt-0040-render-sha-0': 'gpt-4',
      'text-gpt-0035-render-sha-0': 'gpt-3.5-turbo',
      'text-gpt-0035-render-sha-0301': 'gpt-3.5-turbo-0314',
      'text-gpt-0040-render-sha-0314': 'gpt-4-0314',
      'text-gpt-0040-render-sha-turbo': 'gpt-4-turbo',
      'text-gpt-4o-render-sha-0': 'gpt-4o',
      # perfxcloud适配
      'text-gpt-0035-render-sha-0': 'Qwen2-72B-Instruct-GPTQ-Int4',
      'text-gpt-0035-render-sha-0': 'Meta-Llama-3.1-8B-Instruct',
      }
    3. 打开chatgpt-clone/client/html/index.html

      如上图所示,在index.html文件的“model”模块中加入PerfxCloud的适配模型。

      <option value="Meta-Llama-3.1-8B-Instruct">Meta-Llama-3.1-8B-Instruct</option>
      <option value="Qwen2-72B-Instruct-GPTQ-Int4">Qwen2-72B-Instruct-GPTQ-Int4</option>
  3. chatgpt-clone项目运行

    在完成环境配置之后,即可在chatgpt-clone项目的根目录下执行以下代码:

    python3 run.py

    在程序运行起来之后,进入浏览器,在浏览器输入127.0.0.1:1338/chat/并回车,即可进入chatgpt-clone的web页面,如下图所示。

    进入web页面后,可以在web页面选择PerfxCloud的大语言模型,如上图红色框所示,选择完成后即可开始使用。

项目视频

https://www.bilibili.com/video/BV1qS421X7AG/?spm_id_from=333.999.0.0