Skip to content

Commit

Permalink
fix(ai-proxy): missing parsed_url nil check
Browse files Browse the repository at this point in the history
  • Loading branch information
shreemaan-abhishek committed Oct 11, 2024
1 parent 695ea3c commit cee7e62
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
10 changes: 5 additions & 5 deletions apisix/plugins/ai-proxy/drivers/openai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ function _M.request(conf, request_table, ctx)
end

local ok, err = httpc:connect({
scheme = parsed_url.scheme or "https",
host = parsed_url.host or DEFAULT_HOST,
port = parsed_url.port or DEFAULT_PORT,
scheme = endpoint and parsed_url.scheme or "https",
host = endpoint and parsed_url.host or DEFAULT_HOST,
port = endpoint and parsed_url.port or DEFAULT_PORT,
ssl_verify = conf.ssl_verify,
ssl_server_name = parsed_url.host or DEFAULT_HOST,
ssl_server_name = endpoint and parsed_url.host or DEFAULT_HOST,
pool_size = conf.keepalive and conf.keepalive_pool,
})

if not ok then
return nil, "failed to connect to LLM server: " .. err
end

local path = (parsed_url.path or DEFAULT_PATH)
local path = (endpoint and parsed_url.path or DEFAULT_PATH)

local headers = (conf.auth.header or {})
headers["Content-Type"] = "application/json"
Expand Down
66 changes: 66 additions & 0 deletions t/plugin/ai-proxy2.t
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,69 @@ POST /anything
--- error_code: 200
--- response_body
passed
=== TEST 5: set route with right query param
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/anything",
"plugins": {
"ai-proxy": {
"auth": {
"header": {
"Authorization": "some-key"
}
},
"model": {
"provider": "openai",
"name": "gpt-4",
"options": {
"max_tokens": 512,
"temperature": 1.0
}
}
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org": 1
}
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 6: send request
--- yaml_config
apisix:
node_listen: 1984
ssl:
lua_ssl_trusted_certificate: /etc/ssl/certs/ca-certificates.crt
deployment:
role: traditional
role_traditional:
config_provider: etcd
etcd:
host:
- "http://127.0.0.1:2379"
--- request
POST /anything
{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }
--- error_code: 401

0 comments on commit cee7e62

Please sign in to comment.