Skip to content

Commit

Permalink
chore(llm): fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Aug 13, 2024
1 parent 31c7c09 commit c9741da
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
10 changes: 8 additions & 2 deletions kong/llm/drivers/azure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,23 @@ function _M.configure_request(conf)
local auth_param_location = conf.auth and conf.auth.param_location

if auth_header_name and auth_header_value then
kong.service.request.set_header(auth_header_name, auth_header_value)
local exist_value = kong.request.get_header(auth_header_name)
if exist_value == nil or not conf.auth.can_override then
kong.service.request.set_header(auth_header_name, auth_header_value)
end
end


local query_table = kong.request.get_query()

-- technically min supported version
query_table["api-version"] = kong.request.get_query_arg("api-version")
or (conf.model.options and conf.model.options.azure_api_version)

if auth_param_name and auth_param_value and auth_param_location == "query" then
query_table[auth_param_name] = auth_param_value
if query_table[auth_param_name] == nil or not conf.auth.can_override then
query_table[auth_param_name] = auth_param_value
end
end

kong.service.request.set_query(query_table)
Expand Down
11 changes: 8 additions & 3 deletions kong/llm/drivers/cohere.lua
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,18 @@ function _M.configure_request(conf)
local auth_param_location = conf.auth and conf.auth.param_location

if auth_header_name and auth_header_value then
kong.service.request.set_header(auth_header_name, auth_header_value)
local exist_value = kong.request.get_header(auth_header_name)
if exist_value == nil or not conf.auth.can_override then
kong.service.request.set_header(auth_header_name, auth_header_value)
end
end

if auth_param_name and auth_param_value and auth_param_location == "query" then
local query_table = kong.request.get_query()
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
if query_table[auth_param_name] == nil or not conf.auth.can_override then
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
end
end

-- if auth_param_location is "form", it will have already been set in a pre-request hook
Expand Down
12 changes: 9 additions & 3 deletions kong/llm/drivers/gemini.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,20 @@ function _M.configure_request(conf, identity_interface)

-- DBO restrictions makes sure that only one of these auth blocks runs in one plugin config
if auth_header_name and auth_header_value then
kong.service.request.set_header(auth_header_name, auth_header_value)
local exist_value = kong.request.get_header(auth_header_name)
if exist_value == nil or not conf.auth.can_override then
kong.service.request.set_header(auth_header_name, auth_header_value)
end
end

if auth_param_name and auth_param_value and auth_param_location == "query" then
local query_table = kong.request.get_query()
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
if query_table[auth_param_name] == nil or not conf.auth.can_override then
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
end
end

-- if auth_param_location is "form", it will have already been set in a global pre-request hook

-- if we're passed a GCP SDK, for cloud identity / SSO, use it appropriately
Expand Down
11 changes: 8 additions & 3 deletions kong/llm/drivers/llama2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,18 @@ function _M.configure_request(conf)
local auth_param_location = conf.auth and conf.auth.param_location

if auth_header_name and auth_header_value then
kong.service.request.set_header(auth_header_name, auth_header_value)
local exist_value = kong.request.get_header(auth_header_name)
if exist_value == nil or not conf.auth.can_override then
kong.service.request.set_header(auth_header_name, auth_header_value)
end
end

if auth_param_name and auth_param_value and auth_param_location == "query" then
local query_table = kong.request.get_query()
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
if query_table[auth_param_name] == nil or not conf.auth.can_override then
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
end
end

-- if auth_param_location is "form", it will have already been set in a pre-request hook
Expand Down
11 changes: 8 additions & 3 deletions kong/llm/drivers/mistral.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,18 @@ function _M.configure_request(conf)
local auth_param_location = conf.auth and conf.auth.param_location

if auth_header_name and auth_header_value then
kong.service.request.set_header(auth_header_name, auth_header_value)
local exist_value = kong.request.get_header(auth_header_name)
if exist_value == nil or not conf.auth.can_override then
kong.service.request.set_header(auth_header_name, auth_header_value)
end
end

if auth_param_name and auth_param_value and auth_param_location == "query" then
local query_table = kong.request.get_query()
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
if query_table[auth_param_name] == nil or not conf.auth.can_override then
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
end
end

-- if auth_param_location is "form", it will have already been set in a pre-request hook
Expand Down
11 changes: 8 additions & 3 deletions kong/llm/drivers/openai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,18 @@ function _M.configure_request(conf)
local auth_param_location = conf.auth and conf.auth.param_location

if auth_header_name and auth_header_value then
kong.service.request.set_header(auth_header_name, auth_header_value)
local exist_value = kong.request.get_header(auth_header_name)
if exist_value == nil or not conf.auth.can_override then
kong.service.request.set_header(auth_header_name, auth_header_value)
end
end

if auth_param_name and auth_param_value and auth_param_location == "query" then
local query_table = kong.request.get_query()
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
if query_table[auth_param_name] == nil or not conf.auth.can_override then
query_table[auth_param_name] = auth_param_value
kong.service.request.set_query(query_table)
end
end

-- if auth_param_location is "form", it will have already been set in a global pre-request hook
Expand Down

0 comments on commit c9741da

Please sign in to comment.