-
Notifications
You must be signed in to change notification settings - Fork 470
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 ai security guard #1261
base: main
Are you sure you want to change the base?
Update ai security guard #1261
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1261 +/- ##
==========================================
+ Coverage 35.91% 44.31% +8.40%
==========================================
Files 69 75 +6
Lines 11576 9823 -1753
==========================================
+ Hits 4157 4353 +196
+ Misses 7104 5142 -1962
- Partials 315 328 +13 |
| `accessKey` | string | requried | - | Aliyun accesskey | | ||
| `secretKey` | string | requried | - | Aliyun secretkey | | ||
| `checkRequest` | bool | optional | false | check if the input is leagal | | ||
| `checkResponse` | bool | optional | false | check if the output is leagal | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legal
拼写错误。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢董老师捉虫
## 配置示例 | ||
### check if the input is leagal | ||
## Examples of configuration | ||
### Check if the input is leagal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
拼写问题同上
| `accessKey` | string | requried | - | 阿里云AK | | ||
| `secretKey` | string | requried | - | 阿里云SK | | ||
| `checkRequest` | bool | optional | false | 检查提问内容是否合规 | | ||
| `checkResponse` | bool | optional | false | 检查大模型的回答内容是否合规,生效时会使流式响应变为非流式 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
生效时会使流式响应变为非流式
这个可能会影响客户端的行为。是否有办法用流式响应返回对应的结果呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个倒不是技术上的问题,如果要流式返回的话,一个响应要调很多次阿里云内容安全服务了,成本太高了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦,技术上其实也有问题,stream里面发起http请求时,不能够返回actionpause等待请求执行完
config.incrementCounter("ai_sec_request_deny", 1) | ||
proxywasm.SendHttpResponse(200, [][2]string{{"content-type", "text/event-stream;charset=UTF-8"}}, jsonData, -1) | ||
} else { | ||
jsonData := []byte(fmt.Sprintf(NormalResponseFormat, "很抱歉,我不能对您的问题做出回答。")) | ||
jsonData := []byte(fmt.Sprintf(NormalResponseFormat, DefaultResponseIfNoAdvice)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种是不是没必要每次单独构造?
@@ -288,7 +289,7 @@ func onHttpResponseBody(ctx wrapper.HttpContext, config AISecurityConfig, body [ | |||
reqParams.Add(k, v) | |||
} | |||
reqParams.Add("Signature", signature) | |||
config.client.Post(fmt.Sprintf("/?%s", reqParams.Encode()), nil, nil, | |||
config.client.Post(fmt.Sprintf("/?%s", reqParams.Encode()), [][2]string{{"User-Agent", "CIPFrom/AIGateway"}}, nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UA 弄个常量吧
} else { | ||
jsonData = []byte(fmt.Sprintf(NormalResponseFormat, "很抱歉,我不能对您的问题做出回答。")) | ||
jsonData = []byte(fmt.Sprintf(NormalResponseFormat, DefaultResponseIfNoAdvice)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
counter = proxywasm.DefineCounterMetric(metricName) | ||
config.metrics[metricName] = counter | ||
} | ||
counter.Increment(inc) | ||
} | ||
|
||
type StandardResponse struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 struct 没有用到了吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个确实没再用到了,我删除一下
更新内容安全插件: