Skip to content
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

update specs #346

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,21 @@ description: 阿里云内容安全检测
| `responseContentJsonPath` | string | optional | `choices.0.message.content` | 指定要检测内容在响应body中的jsonpath |
| `responseStreamContentJsonPath` | string | optional | `choices.0.delta.content` | 指定要检测内容在流式响应body中的jsonpath |
| `denyCode` | int | optional | 200 | 指定内容非法时的响应状态码 |
| `denyMessage` | string | optional | openai格式的流失/非流式响应,回答内容为阿里云内容安全的建议回答 | 指定内容非法时的响应内容 |

| `denyMessage` | string | optional | openai格式的流式/非流式响应 | 指定内容非法时的响应内容 |
| `protocol` | string | optional | openai | 协议格式,非openai协议填`original` |

补充说明一下 `denyMessage`,对于openai格式的请求,对非法请求的处理逻辑为:
- 如果配置了 `denyMessage`
- 优先返回阿里云内容安全的建议回答,格式为openai格式的流式/非流式响应
- 如果阿里云内容安全未返回建议的回答,返回内容为 `denyMessage` 配置内容,格式为openai格式的流式/非流式响应
- 如果没有配置 `denyMessage`
- 优先返回阿里云内容安全的建议回答,格式为openai格式的流式/非流式响应
- 如果阿里云内容安全未返回建议的回答,返回内容为内置的兜底回答,内容为`"很抱歉,我无法回答您的问题"`,格式为openai格式的流式/非流式响应

如果用户使用了非openai格式的协议,应当配置 `denyMessage`,此时对非法请求的处理逻辑为:
- 返回用户配置的 `denyMessage` 内容,用户可以配置其为序列化后的json字符串,以保持与正常请求接口返回格式的一致性
- 如果 `denyMessage` 为空,优先返回阿里云内容安全的建议回答,格式为纯文本
- 如果阿里云内容安全未返回建议回答,返回内置的兜底回答,内容为`"很抱歉,我无法回答您的问题"`,格式为纯文本

## 配置示例
### 前提条件
Expand Down Expand Up @@ -91,6 +104,7 @@ requestContentJsonPath: "input.prompt"
responseContentJsonPath: "output.text"
denyCode: 200
denyMessage: "很抱歉,我无法回答您的问题"
protocol: original
```

## 可观测
Expand Down Expand Up @@ -123,7 +137,7 @@ curl http://localhost/v1/chat/completions \

```json
{
"id": "chatcmpl-123",
"id": "chatcmpl-AAy3hK1dE4ODaegbGOMoC9VY4Sizv",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o-mini",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Plugin Priority: `300`
| `responseContentJsonPath` | string | optional | `choices.0.message.content` | Specify the jsonpath of the content to be detected in the response body |
| `responseStreamContentJsonPath` | string | optional | `choices.0.delta.content` | Specify the jsonpath of the content to be detected in the streaming response body |
| `denyCode` | int | optional | 200 | Response status code when the specified content is illegal |
| `denyMessage` | string | optional | Drainage/non-streaming response in openai format, the answer content is the suggested answer from Alibaba Cloud content security
| Response content when the specified content is illegal |
| `denyMessage` | string | optional | Drainage/non-streaming response in openai format, the answer content is the suggested answer from Alibaba Cloud content security | Response content when the specified content is illegal |
| `protocol` | string | optional | openai | protocol format, `openai` or `original` |


## Examples of configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ spec:
openAPIV3Schema:
type: object
example:
serviceSource: dns
serviceName: safecheck
serviceName: safecheck.dns # 请先创建好相应服务
servicePort: 443
domain: green-cip.cn-shanghai.aliyuncs.com
ak: xxxxxxxxxxxxxxxxxxxx
sk: xxxxxxxxxxxxxxxxxxxx
serviceHost: green-cip.cn-hangzhou.aliyuncs.com
accessKey: "XXXXXXXXX"
secretKey: "XXXXXXXXXXXXXXX"
checkRequest: true
checkResponse: false
routeConfigSchema:
openAPIV3Schema:
type: object
example:
serviceSource: dns
serviceName: safecheck
serviceName: safecheck.dns # 请先创建好相应服务
servicePort: 443
domain: green-cip.cn-shanghai.aliyuncs.com
ak: xxxxxxxxxxxxxxxxxxxx
sk: xxxxxxxxxxxxxxxxxxxx
serviceHost: green-cip.cn-hangzhou.aliyuncs.com
accessKey: "XXXXXXXXX"
secretKey: "XXXXXXXXXXXXXXX"
checkRequest: true
checkResponse: false

24 changes: 22 additions & 2 deletions backend/sdk/src/main/resources/plugins/ai-statistics/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,29 @@ spec:
openAPIV3Schema:
type: object
example:
enable: true
routeConfigSchema:
openAPIV3Schema:
type: object
example:
enable: true
# attributes:
# - key: consumer # 配合认证鉴权记录consumer
# value_source: request_header
# value: x-mse-consumer
# apply_to_log: true # 是否将信息添加到日志中
# apply_to_span: false # 是否将信息添加到链路追踪span attribute中
# - key: question # 记录问题
# value_source: request_body
# value: [email protected]
# apply_to_log: true
# apply_to_span: false
# - key: answer # 在流式响应中提取大模型的回答
# value_source: response_streaming_body
# value: choices.0.delta.content
# rule: append
# apply_to_log: true
# apply_to_span: false
# - key: answer # 在非流式响应中提取大模型的回答
# value_source: response_body
# value: choices.0.message.content
# apply_to_log: true
# apply_to_span: false
Loading