Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

教程:使用 Higress + LobeChat 对接通义千问 (支持 RAG、联网) #3035

Closed
johnlanni opened this issue Jun 25, 2024 · 1 comment

Comments

@johnlanni
Copy link

第一步:创建一个名为 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:https://higress:8080/v1
    networks:
      - higress-net
    ports:
      - "3210:3210/tcp"
    restart: always

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

docker compose -p higress-ai up -d

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

image

Tips 1:开启联网搜索能力

在浏览器里访问 http:https://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:https://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 项目一个 star:https://github.com/alibaba/higress

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

@lobehubbot
Copy link
Member

👀 @johnlanni

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible.
非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

@johnlanni johnlanni changed the title 教程:使用 Higress + LobeChat 对接通义千问做问答助手 (支持 RAG、联网) 教程:使用 Higress + LobeChat 对接通义千问 (支持 RAG、联网) Jun 25, 2024
@lobehub lobehub locked and limited conversation to collaborators Jun 25, 2024
@arvinxx arvinxx converted this issue into discussion #3036 Jun 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants