Skip to content

Commit

Permalink
Merge branch 'master' of github.com:apache/apisix into revolyssup/bac…
Browse files Browse the repository at this point in the history
…kport/anonymousconsumer
  • Loading branch information
Revolyssup committed Dec 16, 2024
2 parents 74a2748 + f3c81b5 commit 40ce255
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 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
4 changes: 3 additions & 1 deletion t/APISIX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ _EOC_
$block->set_value("stream_config", $stream_config);
}

my $custom_trusted_cert = $block->custom_trusted_cert // 'cert/apisix.crt';

my $stream_server_config = $block->stream_server_config // <<_EOC_;
listen 2005 ssl;
ssl_certificate cert/apisix.crt;
Expand Down Expand Up @@ -737,7 +739,7 @@ _EOC_
http3 off;
ssl_certificate cert/apisix.crt;
ssl_certificate_key cert/apisix.key;
lua_ssl_trusted_certificate cert/apisix.crt;
lua_ssl_trusted_certificate $custom_trusted_cert;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
Expand Down
55 changes: 55 additions & 0 deletions t/plugin/ai-proxy2.t
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,58 @@ POST /anything
--- error_code: 200
--- response_body
passed
=== TEST 5: set route without overriding the endpoint_url
--- 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
--- custom_trusted_cert: /etc/ssl/certs/ca-certificates.crt
--- 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 40ce255

Please sign in to comment.