feature: add ai-intent plugin (#1237)

Signed-off-by: jose <313503823@qq.com>
This commit is contained in:
jose
2024-08-27 19:25:18 +08:00
committed by GitHub
parent 75e1defd6c
commit 2c1773a7f0
6 changed files with 472 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
## 简介
**Note**
> 需要数据面的proxy wasm版本大于等于0.2.100
> 编译时需要带上版本的tag例如`tinygo build -o main.wasm -scheduler=none -target=wasi -gc=custom -tags="custommalloc nottinygc_finalizer proxy_wasm_version_0_2_100" ./`
LLM 意图识别插件能够智能判断用户请求与某个领域或agent的功能契合度从而提升不同模型的应用效果和用户体验
## 配置说明
> 1.该插件的优先级要高于ai-cache、ai-proxy等后续使用意图的插件后续插件可以通过proxywasm.GetProperty([]string{"intent_category"})方法获取到意图主题,按照意图主题去做不同缓存库或者大模型的选择
> 2.需新建一条higress的大模型路由供该插件访问大模型,如:路由以 /intent 作为前缀服务选择大模型服务为该路由开启ai-proxy插件
> 3.需新建一个固定地址的服务intent-service服务指向127.0.0.1:80 (即自身网关实例+端口ai-intent插件内部需要该服务进行调用以访问上述新增的路由,服务名对应 llm.proxyServiceName也可以新建DNS类型服务使插件访问其他大模型
> 4.如果使用固定地址的服务调用网关自身需把127.0.0.1加入到网关的访问白名单中
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
| -------------- | --------------- | -------- | ------ | ------------------------------------------------------------ |
| `scene.category` | string | 必填 | - | 预设场景类别,以"|"分割,如:"金融|电商|法律|Higress"|
| `scene.prompt` | string | 非必填 | 你是一个智能类别识别助手,负责根据用户提出的问题和预设的类别,确定问题属于哪个预设的类别,并给出相应的类别。用户提出的问题为:%s,预设的类别为%s直接返回一种具体类别如果没有找到就返回'NotFound'。 | llm请求prompt模板 |
| `llm.proxyServiceName` | string | 必填 | - | 新建的higress服务指向大模型 (取higress中的 FQDN 值)|
| `llm.proxyUrl` | string | 必填 | - | 大模型路由请求地址全路径可以是网关自身的地址也可以是其他大模型的地址openai协议例如http://127.0.0.1:80/intent/compatible-mode/v1/chat/completions |
| `llm.proxyDomain` | string | 非必填 | proxyUrl中解析获取 | 大模型服务的domain|
| `llm.proxyPort` | string | 非必填 | proxyUrl中解析获取 | 大模型服务端口号 |
| `llm.proxyApiKey` | string | 非必填 | - | 当使用外部大模型服务时需配置 对应大模型的 API_KEY |
| `llm.proxyModel` | string | 非必填 | qwen-long | 大模型类型 |
| `llm.proxyTimeout` | number | 非必填 | 10000 | 调用大模型超时时间单位ms默认10000ms |
## 配置示例
```yaml
scene:
category: "金融|电商|法律|Higress"
prompt: "你是一个智能类别识别助手,负责根据用户提出的问题和预设的类别,确定问题属于哪个预设的类别,并给出相应的类别。用户提出的问题为:'%s',预设的类别为'%s',直接返回一种具体类别,如果没有找到就返回'NotFound'。"
llm:
proxyServiceName: "intent-service.static"
proxyUrl: "http://127.0.0.1:80/intent/compatible-mode/v1/chat/completions"
proxyDomain: "127.0.0.1"
proxyPort: "80"
proxyModel: "qwen-long"
proxyApiKey: ""
proxyTimeout: "10000"
```