feat: add url_join (#856)
This commit is contained in:
parent
8bbcd64550
commit
dfc51b3247
9
.github/workflows/ci.yaml
vendored
9
.github/workflows/ci.yaml
vendored
@ -14,11 +14,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
|
||||||
- uses: JohnnyMorganz/stylua-action@b6661824b86c9c33121bed87a778b660ba90cf77 # ratchet:JohnnyMorganz/stylua-action@v4
|
- name: Install stylua
|
||||||
|
uses: baptiste0928/cargo-install@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
crate: stylua
|
||||||
version: latest
|
features: lua54
|
||||||
args: --check ./lua/ ./plugin/
|
- run: stylua --check ./lua/ ./plugin/
|
||||||
luacheck:
|
luacheck:
|
||||||
name: Lint Lua
|
name: Lint Lua
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -8,7 +8,7 @@ repos:
|
|||||||
- repo: https://github.com/JohnnyMorganz/StyLua
|
- repo: https://github.com/JohnnyMorganz/StyLua
|
||||||
rev: v0.20.0
|
rev: v0.20.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: stylua-github # or stylua-system / stylua-github
|
- id: stylua-system # or stylua-system / stylua-github
|
||||||
files: \.lua$
|
files: \.lua$
|
||||||
- repo: https://github.com/doublify/pre-commit-rust
|
- repo: https://github.com/doublify/pre-commit-rust
|
||||||
rev: master
|
rev: master
|
||||||
|
@ -25,11 +25,10 @@ M.parse_curl_args = function(provider, code_opts)
|
|||||||
if not P.env.is_local("azure") then headers["api-key"] = provider.parse_api_key() end
|
if not P.env.is_local("azure") then headers["api-key"] = provider.parse_api_key() end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url = Utils.trim(base.endpoint, { suffix = "/" })
|
url = Utils.url_join(
|
||||||
.. "/openai/deployments/"
|
base.endpoint,
|
||||||
.. base.deployment
|
"/openai/deployments/" .. base.deployment .. "/chat/completions?api-version=" .. base.api_version
|
||||||
.. "/chat/completions?api-version="
|
),
|
||||||
.. base.api_version,
|
|
||||||
proxy = base.proxy,
|
proxy = base.proxy,
|
||||||
insecure = base.allow_insecure,
|
insecure = base.allow_insecure,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
|
@ -106,7 +106,7 @@ M.parse_curl_args = function(provider, prompt_opts)
|
|||||||
local messages = M.parse_messages(prompt_opts)
|
local messages = M.parse_messages(prompt_opts)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url = Utils.trim(base.endpoint, { suffix = "/" }) .. "/v1/messages",
|
url = Utils.url_join(base.endpoint, "/v1/messages"),
|
||||||
proxy = base.proxy,
|
proxy = base.proxy,
|
||||||
insecure = base.allow_insecure,
|
insecure = base.allow_insecure,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
|
@ -85,7 +85,7 @@ M.parse_curl_args = function(provider, code_opts)
|
|||||||
if not P.env.is_local("cohere") then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
if not P.env.is_local("cohere") then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url = Utils.trim(base.endpoint, { suffix = "/" }) .. "/chat",
|
url = Utils.url_join(base.endpoint, "/chat"),
|
||||||
proxy = base.proxy,
|
proxy = base.proxy,
|
||||||
insecure = base.allow_insecure,
|
insecure = base.allow_insecure,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
|
@ -86,11 +86,10 @@ M.parse_curl_args = function(provider, code_opts)
|
|||||||
body_opts.max_tokens = nil
|
body_opts.max_tokens = nil
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url = Utils.trim(base.endpoint, { suffix = "/" })
|
url = Utils.url_join(
|
||||||
.. "/"
|
base.endpoint,
|
||||||
.. base.model
|
base.model .. ":streamGenerateContent?alt=sse&key=" .. provider.parse_api_key()
|
||||||
.. ":streamGenerateContent?alt=sse&key="
|
),
|
||||||
.. provider.parse_api_key(),
|
|
||||||
proxy = base.proxy,
|
proxy = base.proxy,
|
||||||
insecure = base.allow_insecure,
|
insecure = base.allow_insecure,
|
||||||
headers = { ["Content-Type"] = "application/json" },
|
headers = { ["Content-Type"] = "application/json" },
|
||||||
|
@ -136,7 +136,7 @@ M.parse_curl_args = function(provider, code_opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url = Utils.trim(base.endpoint, { suffix = "/" }) .. "/chat/completions",
|
url = Utils.url_join(base.endpoint, "/chat/completions"),
|
||||||
proxy = base.proxy,
|
proxy = base.proxy,
|
||||||
insecure = base.allow_insecure,
|
insecure = base.allow_insecure,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
|
@ -438,6 +438,32 @@ function M.trim_spaces(s) return s:match("^%s*(.-)%s*$") end
|
|||||||
|
|
||||||
function M.fallback(v, default_value) return type(v) == "nil" and default_value or v end
|
function M.fallback(v, default_value) return type(v) == "nil" and default_value or v end
|
||||||
|
|
||||||
|
---Join URL parts together, handling slashes correctly
|
||||||
|
---@param ... string URL parts to join
|
||||||
|
---@return string Joined URL
|
||||||
|
function M.url_join(...)
|
||||||
|
local parts = { ... }
|
||||||
|
local result = parts[1] or ""
|
||||||
|
|
||||||
|
for i = 2, #parts do
|
||||||
|
local part = parts[i]
|
||||||
|
if not part or part == "" then goto continue end
|
||||||
|
|
||||||
|
-- Remove trailing slash from result if present
|
||||||
|
if result:sub(-1) == "/" then result = result:sub(1, -2) end
|
||||||
|
|
||||||
|
-- Remove leading slash from part if present
|
||||||
|
if part:sub(1, 1) == "/" then part = part:sub(2) end
|
||||||
|
|
||||||
|
-- Join with slash
|
||||||
|
result = result .. "/" .. part
|
||||||
|
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
-- luacheck: push no max comment line length
|
-- luacheck: push no max comment line length
|
||||||
---@param type_name "'nil'" | "'number'" | "'string'" | "'boolean'" | "'table'" | "'function'" | "'thread'" | "'userdata'" | "'list'" | '"map"'
|
---@param type_name "'nil'" | "'number'" | "'string'" | "'boolean'" | "'table'" | "'function'" | "'thread'" | "'userdata'" | "'list'" | '"map"'
|
||||||
---@return boolean
|
---@return boolean
|
||||||
|
Loading…
x
Reference in New Issue
Block a user