higress icon indicating copy to clipboard operation
higress copied to clipboard

使用 Higress + LobeChat 快速搭建私人GPT助理(支持 RAG、联网)

Open johnlanni opened this issue 8 months ago • 44 comments

第一步:创建一个名为 docker-compose.yml 的文件,并填入以下内容:

注意:

  1. YOUR_DASHSCOPE_API_KEY 需要替换为你自己的通义千问的 API Key
  2. /path-to-local-config-folder 需要替换为一个本地可以用来保存配置文件的目录路径。
  3. CODE=访问密码 这里换成你自己的密码
version: '3.9'

networks:
  higress-net:
    external: false

services:
  higress:
    image: higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/all-in-one:1.4.1
    environment:
      - CONFIG_TEMPLATE=ai-proxy
      - DEFAULT_AI_SERVICE=qwen
      - DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
    networks:
      - higress-net
    ports:
      - "8080:8080/tcp"
      - "8001:8001/tcp"
    volumes:
      - /path-to-local-config-folder:/data
    restart: always
  lobechat:
    # docker hub 如果访问不了,可以改用这个地址:registry.cn-hangzhou.aliyuncs.com/2456868764/lobe-chat:v1.1.3
    image: lobehub/lobe-chat
    environment:
      - CODE=访问密码
      - OPENAI_API_KEY=unused
      - OPENAI_PROXY_URL=http://higress:8080/v1
    networks:
      - higress-net
    ports:
      - "3210:3210/tcp"
    restart: always

第二步:在命令行中运行以下命令,启动 docker compose 项目:

docker compose -p higress-ai up -d

第三步:在浏览器里访问 http://localhost:3210/ 打开 LobeChat 页面;

image

Tips 1:开启联网搜索能力

在浏览器里访问 http://localhost:8001/ 打开 Higress 控制台

image

image

在这里做配置调整:

provider:
  apiTokens:
  - "你的Dashscope API Key"
  # openai 模型到 qwen 的模型映射,qwen-long 最便宜,百万token 5毛钱,qwen-max 效果最好
  modelMapping:
    '*': "qwen-long"
    gpt-4: "qwen-max"
    gpt-4-turbo: "qwen-max"
    gpt-4o: "qwen-max"
  type: "qwen"
  # 开启联网搜索能力
  qwenEnableSearch: true

Tips 2:开启 RAG 能力

在浏览器里访问 http://localhost:8001/ 打开 Higress 控制台

image

上传一份文件用于 RAG (详细可以查看这里的文档):

curl --location --request POST 'https://dashscope.aliyuncs.com/compatible-mode/v1/files' \
  --header 'Authorization: Bearer 这里填APIKey' \
  --form 'file=@" ./doc.md"' \
  --form 'purpose="file-extract"'

# 返回内容:
{"id":"file-fe-xxxxxxx","object":"file","bytes":596687,"created_at":1716635947,"filename":"doc.md","purpose":"file-extract","status":"processed"}

image

在这里做配置调整:

provider:
  apiTokens:
  - "你的Dashscope API Key"
  # openai 模型到 qwen 的模型映射,qwen-long 最便宜,百万token 5毛钱,qwen-max 效果最好
  modelMapping:
    '*': "qwen-long"
    gpt-4: "qwen-max"
    gpt-4-turbo: "qwen-max"
    gpt-4o: "qwen-max"
  type: "qwen"
  # 在这里配置上面的 file id
  qwenFileIds:
  - "file-fe-xxxxxxx"

注意 RAG 只有 qwen-long 支持,且文件内容转变为 token 数,每次请求都会加上进行计费

其他

Higress AI 相关插件的详细文档可以查阅:https://higress.io/zh-cn/docs/plugins/ai/ai-proxy

johnlanni avatar May 31 '24 08:05 johnlanni