AlinsRan commented on code in PR #13406:
URL: https://github.com/apache/apisix/pull/13406#discussion_r3279669464
##########
t/plugin/ai-proxy-request-body-override.t:
##########
@@ -174,7 +174,129 @@ __DATA__
-=== TEST 3: llm_options: openai provider maps max_tokens to
max_completion_tokens
+=== TEST 3a: ai-proxy forwards the original body when it is not rewritten
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "uri": "/chat",
+ "plugins": {
+ "ai-proxy": {
+ "provider": "openai-compatible",
+ "auth": { "header": { "Authorization": "Bearer t"
} },
+ "override": {
+ "endpoint": "http://localhost:6732"
+ },
+ "ssl_verify": false
+ }
+ }
+ }]]
+ )
+ if code >= 300 then ngx.status = code; return end
+
+ local raw = '{ "messages" : [ { "role" : "user", "content" : "hi"
} ], "temperature" : 0.7 }'
+ local http = require("resty.http").new()
+ local res = assert(http:request_uri("http://127.0.0.1:" ..
ngx.var.server_port .. "/chat", {
+ method = "POST",
+ body = raw,
+ headers = { ["Content-Type"] = "application/json" },
+ }))
+ local cjson = require("cjson.safe")
+ local body = cjson.decode(res.body)
+ ngx.say(body.choices[1].message.content == raw and "same body" or
"body changed")
+ }
+ }
+--- response_body
+same body
+
+
+
+=== TEST 4b: ai-proxy-multi forwards the original body when it is not rewritten
Review Comment:
```
===TEST 4a
===TEST 4b
```
At this point, Lint will fail.
##########
t/plugin/ai-proxy-request-body-override.t:
##########
@@ -174,7 +174,129 @@ __DATA__
-=== TEST 3: llm_options: openai provider maps max_tokens to
max_completion_tokens
+=== TEST 3a: ai-proxy forwards the original body when it is not rewritten
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "uri": "/chat",
+ "plugins": {
+ "ai-proxy": {
+ "provider": "openai-compatible",
+ "auth": { "header": { "Authorization": "Bearer t"
} },
+ "override": {
+ "endpoint": "http://localhost:6732"
+ },
+ "ssl_verify": false
+ }
+ }
+ }]]
+ )
+ if code >= 300 then ngx.status = code; return end
+
+ local raw = '{ "messages" : [ { "role" : "user", "content" : "hi"
} ], "temperature" : 0.7 }'
+ local http = require("resty.http").new()
+ local res = assert(http:request_uri("http://127.0.0.1:" ..
ngx.var.server_port .. "/chat", {
+ method = "POST",
+ body = raw,
+ headers = { ["Content-Type"] = "application/json" },
+ }))
+ local cjson = require("cjson.safe")
+ local body = cjson.decode(res.body)
+ ngx.say(body.choices[1].message.content == raw and "same body" or
"body changed")
+ }
+ }
+--- response_body
+same body
+
+
+
+=== TEST 4b: ai-proxy-multi forwards the original body when it is not rewritten
Review Comment:
```
===TEST 4a
...
===TEST 4b
```
At this point, Lint will fail.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]