Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hanxiantao/higress into syn…
Browse files Browse the repository at this point in the history
…c-gateway-api-status
  • Loading branch information
hanxiantao committed Sep 22, 2024
2 parents 5ebc059 + ffc5458 commit d3081ec
Show file tree
Hide file tree
Showing 13 changed files with 680 additions and 379 deletions.
43 changes: 26 additions & 17 deletions plugins/wasm-go/extensions/ai-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ description: AI Agent插件配置参考
---

## 功能说明
一个可定制化的 API AI Agent,支持配置 http method 类型为 GET 与 POST 的 API,目前只支持非流式模式
一个可定制化的 API AI Agent,支持配置 http method 类型为 GET 与 POST 的 API,支持多轮对话,支持流式与非流式模式
agent流程图如下:
![ai-agent](https://github.com/user-attachments/assets/b0761a0c-1afa-496c-a98e-bb9f38b340f8)

## 运行属性

插件执行阶段:`默认阶段`
插件执行优先级:`20`

## 配置字段

Expand Down Expand Up @@ -46,18 +42,19 @@ agent流程图如下:

`apiProvider`的配置字段说明如下:

| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|-----------------|-----------|---------|--------|------------------------------------------|
| `apiKey` | object | 非必填 | - | 用于在访问外部 API 服务时进行认证的令牌。 |
| `serviceName` | string | 必填 | - | 访问外部 API 服务名 |
| `servicePort` | int | 必填 | - | 访问外部 API 服务端口 |
| `domain` | string | 必填 | - | 访访问外部 API 时域名 |
| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|-------------------|-----------|---------|--------|------------------------------------------|
| `apiKey` | object | 非必填 | - | 用于在访问外部 API 服务时进行认证的令牌。 |
| `maxExecutionTime`| int | 非必填 | 50000 | 每一次请求API的超时时间,单位毫秒。 |
| `serviceName` | string | 必填 | - | 访问外部 API 服务名 |
| `servicePort` | int | 必填 | - | 访问外部 API 服务端口 |
| `domain` | string | 必填 | - | 访访问外部 API 时域名 |

`apiKey`的配置字段说明如下:

| 名称 | 数据类型 | 填写要求 | 默认值 | 描述 |
|-------------------|---------|------------|--------|-------------------------------------------------------------------------------|
| `in` | string | 非必填 | header | 在访问外部 API 服务时进行认证的令牌是放在 header 中还是放在 query 中,默认是 header
|-------------------|---------|------------|--------|-----------------------------------------------------------------------------------------|
| `in` | string | 非必填 | none | 在访问外部 API 服务时进行认证的令牌是放在 header 中还是放在 query 中,如果API没有令牌,填none
| `name` | string | 非必填 | - | 用于在访问外部 API 服务时进行认证的令牌的名称。 |
| `value` | string | 非必填 | - | 用于在访问外部 API 服务时进行认证的令牌的值。 |

Expand All @@ -75,11 +72,8 @@ agent流程图如下:
|-----------------|-----------|-----------|--------|---------------------------------------------|
| `question` | string | 非必填 | - | Agent ReAct 模板的 question 部分 |
| `thought1` | string | 非必填 | - | Agent ReAct 模板的 thought1 部分 |
| `actionInput` | string | 非必填 | - | Agent ReAct 模板的 actionInput 部分 |
| `observation` | string | 非必填 | - | Agent ReAct 模板的 observation 部分 |
| `thought2` | string | 非必填 | - | Agent ReAct 模板的 thought2 部分 |
| `finalAnswer` | string | 非必填 | - | Agent ReAct 模板的 finalAnswer 部分 |
| `begin` | string | 非必填 | - | Agent ReAct 模板的 begin 部分 |

## 用法示例

Expand Down Expand Up @@ -325,6 +319,21 @@ curl 'http://<这里换成网关公网IP>/api/openai/v1/chat/completions' \

**请求示例**

```shell
curl 'http://<这里换成网关公网IP>/api/openai/v1/chat/completions' \
-H 'Accept: application/json, text/event-stream' \
-H 'Content-Type: application/json' \
--data-raw '{"model":"qwen","frequency_penalty":0,"max_tokens":800,"stream":false,"messages":[{"role": "user","content": "济南的天气如何?"},{ "role": "assistant","content": "目前,济南市的天气为多云,气温为24℃,数据更新时间为2024年9月12日21时50分14秒。"},{"role": "user","content": "北京呢?"}],"presence_penalty":0,"temperature":0,"top_p":0}'
```

**响应示例**

```json
{"id":"ebd6ea91-8e38-9e14-9a5b-90178d2edea4","choices":[{"index":0,"message":{"role":"assistant","content":"目前,北京市的天气为晴朗,气温为19℃,数据更新时间为2024年9月12日22时17分40秒。"},"finish_reason":"stop"}],"created":1723187991,"model":"qwen-max-0403","object":"chat.completion","usage":{"prompt_tokens":999,"completion_tokens":76,"total_tokens":1075}}
```

**请求示例**

```shell
curl 'http://<这里换成网关公网IP>/api/openai/v1/chat/completions' \
-H 'Accept: application/json, text/event-stream' \
Expand All @@ -351,4 +360,4 @@ curl 'http://<这里换成网关公网IP>/api/openai/v1/chat/completions' \

```json
{"id":"65dcf12c-61ff-9e68-bffa-44fc9e6070d5","choices":[{"index":0,"message":{"role":"assistant","content":" “九头蛇万岁!”的德语翻译为“Hoch lebe Hydra!”。"},"finish_reason":"stop"}],"created":1724043865,"model":"qwen-max-0403","object":"chat.completion","usage":{"prompt_tokens":908,"completion_tokens":52,"total_tokens":960}}
```
```
31 changes: 20 additions & 11 deletions plugins/wasm-go/extensions/ai-agent/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords: [ AI Gateway, AI Agent ]
description: AI Agent plugin configuration reference
---
## Functional Description
A customizable API AI Agent that supports configuring HTTP method types as GET and POST APIs. Currently, it only supports non-streaming mode.
A customizable API AI Agent that supports configuring HTTP method types as GET and POST APIs. Supports multiple dialogue rounds, streaming and non-streaming modes.
The agent flow chart is as follows:
![ai-agent](https://github.com/user-attachments/assets/b0761a0c-1afa-496c-a98e-bb9f38b340f8)

Expand Down Expand Up @@ -41,17 +41,18 @@ The configuration fields for `apis` are as follows:
| `api` | string | Required | - | OpenAPI documentation of the tool |

The configuration fields for `apiProvider` are as follows:
| Name | Data Type | Requirement | Default Value | Description |
|-----------------|-----------|-------------|---------------|--------------------------------------------------|
| `apiKey` | object | Optional | - | Token for authentication when accessing external API services. |
| `serviceName` | string | Required | - | Name of the external API service |
| `servicePort` | int | Required | - | Port of the external API service |
| `domain` | string | Required | - | Domain for accessing the external API |
| Name | Data Type | Requirement | Default Value | Description |
|-------------------|-----------|-------------|---------------|--------------------------------------------------|
| `apiKey` | object | Optional | - | Token for authentication when accessing external API services. |
| `maxExecutionTime`| int | Optional | 50000 | Timeout for each request to the API, in milliseconds|
| `serviceName` | string | Required | - | Name of the external API service |
| `servicePort` | int | Required | - | Port of the external API service |
| `domain` | string | Required | - | Domain for accessing the external API |

The configuration fields for `apiKey` are as follows:
| Name | Data Type | Requirement | Default Value | Description |
|-------------------|-----------|-------------|---------------|-------------------------------------------------------------------------------------|
| `in` | string | Optional | header | Whether the authentication token for accessing the external API service is in the header or in the query; default is header. |
| `in` | string | Optional | none | Whether the authentication token for accessing the external API service is in the header or in the query; If the API does not have a token, fill in none. |
| `name` | string | Optional | - | The name of the token for authentication when accessing the external API service. |
| `value` | string | Optional | - | The value of the token for authentication when accessing the external API service. |

Expand All @@ -67,11 +68,8 @@ The configuration fields for `chTemplate` and `enTemplate` are as follows:
|-----------------|-----------|-------------|---------------|---------------------------------------------------|
| `question` | string | Optional | - | The question part of the Agent ReAct template |
| `thought1` | string | Optional | - | The thought1 part of the Agent ReAct template |
| `actionInput` | string | Optional | - | The actionInput part of the Agent ReAct template |
| `observation` | string | Optional | - | The observation part of the Agent ReAct template |
| `thought2` | string | Optional | - | The thought2 part of the Agent ReAct template |
| `finalAnswer` | string | Optional | - | The finalAnswer part of the Agent ReAct template |
| `begin` | string | Optional | - | The begin part of the Agent ReAct template |

## Usage Example
**Configuration Information**
Expand Down Expand Up @@ -308,6 +306,17 @@ curl 'http://<replace with gateway public IP>/api/openai/v1/chat/completions' \
curl 'http://<replace with gateway public IP>/api/openai/v1/chat/completions' \
-H 'Accept: application/json, text/event-stream' \
-H 'Content-Type: application/json' \
--data-raw '{"model":"qwen","frequency_penalty":0,"max_tokens":800,"stream":false,"messages":[{"role":"user","content":"What is the current weather in Jinan?"},{"role":"assistant","content":" The current weather condition in Jinan is overcast, with a temperature of 31°C. This information was last updated on August 9, 2024, at 15:12 (Beijing time)."},{"role":"user","content":"BeiJing?"}],"presence_penalty":0,"temperature":0,"top_p":0}'
```
**Response Example**
```json
{"id":"ebd6ea91-8e38-9e14-9a5b-90178d2edea4","choices":[{"index":0,"message":{"role":"assistant","content":" The current weather condition in Beijing is overcast, with a temperature of 19°C. This information was last updated on Sep 12, 2024, at 22:17 (Beijing time)."},"finish_reason":"stop"}],"created":1723187991,"model":"qwen-max-0403","object":"chat.completion","usage":{"prompt_tokens":999,"completion_tokens":76,"total_tokens":1075}}
```
**Request Example**
```shell
curl 'http://<replace with gateway public IP>/api/openai/v1/chat/completions' \
-H 'Accept: application/json, text/event-stream' \
-H 'Content-Type: application/json' \
--data-raw '{"model":"qwen","frequency_penalty":0,"max_tokens":800,"stream":false,"messages":[{"role":"user","content":"What is the current weather in Jinan? Please indicate in Fahrenheit and respond in Japanese."}],"presence_penalty":0,"temperature":0,"top_p":0}'
```
**Response Example**
Expand Down
Loading

0 comments on commit d3081ec

Please sign in to comment.