天池大赛Higress插件官方demo详细部署+调试
type
status
date
slug
summary
tags
category
icon
password
契机前期准备本地搭建调试docker运行higresshigress管理页面配置创建服务来源路由配置配置AI代理插件LLM访问验证官方demo添加加点日志打包插件+push添加ai-cache插件访问日志查看配置+启动插件验证ai-cache迭代升级写到最后
契机
使用Higress AI网关优化AI调用成本。就是基于向量召回相似问题的缓存,降低LLM API调用成本。就是开发一个网关插件做QA缓存嘛。前文已经成功复现了hello-world插件,这次结合官方提供的AI-Cache插件自己动手改改,再写点注释放到天池大赛去跑跑分,环境搭建起来确实有很多要注意的地方,所以记录下来。
前期准备
文档中所有变量都是${your_qwen_token}这种形式,需要你自己替换

本地搭建调试
docker运行higress
higress管理页面配置
此时容器运行起来了,访问http://localhost:8001,进入higress管理页面,密码随便
创建服务来源
首先创建官方文档中的DNS类型的服务,域名是 dashscope.aliyuncs.com,端口是443

然后创建一个redis固定地址服务来源,服务地址写127.0.0.1:6379,名称直接写redis

最后你的服务来源应该如下

路由配置
创建一条前缀匹配/的路由,转发给上面创建的服务,并附加注解:
higress.io/backend-protocol: HTTPS
higress.io/proxy-ssl-name: dashscope.aliyuncs.com
higress.io/proxy-ssl-server-name: on
就按照下图填写就完了

配置AI代理插件
这里要把插件打开,并且把${your_qwen_token},${your_file_id}填写上去

LLM访问验证
上面配置好了,此时你的llm就可以使用了
官方demo添加
加点日志
上面我们已经把项目拷贝下来了,找到官方ai-cache的demo的parseConfig方法,在这里加点日志,等下我们去观察日志插件是否生效

打包插件+push
添加ai-cache插件
继续访问higress管理页面http://localhost:8001,新增插件
插件名称:ai-cache
镜像地址:上面你推送过去的地址,这个的ocl://前缀可以不填写,他是自己加上的
执行阶段:认证阶段
优先级:99
~现在插件没有启动,还要其他配置

访问日志查看
配置+启动插件
这里要先复制,再开启,配置如下

此时看看刚才我们开启的日志,出现以下字样说明没问题了

验证ai-cache
迭代升级
后续去higress管理页面,修改ai-cache的镜像地址就行 所以每次代码更新,需要打包代码,打包镜像,推送到docker仓库,修改插件镜像地址
写到最后
Last update: 2024-06-26