Skip to content

Commit 3060402

Browse files
committed
add license
1 parent ca50ae4 commit 3060402

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

apisix/plugins/ai-prompt-guard.lua

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
--
2+
-- Licensed to the Apache Software Foundation (ASF) under one or more
3+
-- contributor license agreements. See the NOTICE file distributed with
4+
-- this work for additional information regarding copyright ownership.
5+
-- The ASF licenses this file to You under the Apache License, Version 2.0
6+
-- (the "License"); you may not use this file except in compliance with
7+
-- the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing, software
12+
-- distributed under the License is distributed on an "AS IS" BASIS,
13+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
-- See the License for the specific language governing permissions and
15+
-- limitations under the License.
16+
--
117
local core = require("apisix.core")
218
local ngx = ngx
319

@@ -41,7 +57,6 @@ end
4157
local function get_content_to_check(conf, messages)
4258
local contents = {}
4359
if conf.match_all_conversation_history then
44-
core.log.warn("Matching all conversation history")
4560
for _, msg in ipairs(messages) do
4661
if msg.content then
4762
core.table.insert(contents, msg.content)
@@ -61,7 +76,7 @@ end
6176
function _M.access(conf, ctx)
6277
local body = core.request.get_body()
6378
if not body then
64-
core.log.error("Empty request body")
79+
core.log.error("Empty request body")
6580
return core.response.exit(400, {message = "Empty request body"})
6681
end
6782

@@ -72,9 +87,9 @@ function _M.access(conf, ctx)
7287

7388

7489
local messages = json_body.messages or {}
75-
if not conf.match_all_roles and messages and messages[#messages].role ~= "user" then
76-
return
77-
end
90+
if not conf.match_all_roles and messages and messages[#messages].role ~= "user" then
91+
return
92+
end
7893
local content_to_check = get_content_to_check(conf, messages)
7994

8095
-- Allow patterns check

t/plugin/ai-prompt-guard.t

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
117
use t::APISIX 'no_plan';
218

319
add_block_preprocessor(sub {

0 commit comments

Comments
 (0)