bzp2010 commented on code in PR #11499: URL: https://github.com/apache/apisix/pull/11499#discussion_r1745000951
########## apisix/plugins/ai-proxy/drivers/openai.lua: ########## @@ -0,0 +1,83 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +local _M = {} + +local core = require("apisix.core") +local http = require("resty.http") + +local pairs = pairs + +-- globals +local DEFAULT_HOST = "api.openai.com" +local DEFAULT_PORT = 443 + + +function _M.request(conf, request_table, ctx) + local httpc, err = http.new() + if not httpc then + return nil, "failed to create http client to send request to LLM server: " .. err + end + httpc:set_timeout(conf.timeout) + + local custom_host = core.table.try_read_attr(conf, "override", "host") + local custom_port = core.table.try_read_attr(conf, "override", "port") + local custom_path = core.table.try_read_attr(conf, "override", "path") + local custom_scheme = core.table.try_read_attr(conf, "override", "scheme") + + local ok, err = httpc:connect({ + scheme = custom_scheme or "https", + host = custom_host or DEFAULT_HOST, + port = custom_port or DEFAULT_PORT, + ssl_verify = conf.ssl_verify, + ssl_server_name = custom_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 params = { + method = "POST", + headers = { + ["Content-Type"] = "application/json", + }, + keepalive = conf.keepalive, + ssl_verify = conf.ssl_verify, + path = custom_path or "/v1/chat/completions", + } + + if conf.auth.type == "header" then + params.headers[conf.auth.name] = conf.auth.value + end Review Comment: So should it still be kept? ``` if conf.auth.type == "header" then params.headers[conf.auth.name] = conf.auth.value end ``` -- 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]
