fix(style): add parentheses (#471)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
---@field temperature number
|
||||
---@field max_tokens number
|
||||
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
local O = require("avante.providers").openai
|
||||
|
||||
---@class AvanteProviderFunctor
|
||||
@@ -23,7 +23,7 @@ M.parse_curl_args = function(provider, code_opts)
|
||||
local headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
}
|
||||
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 {
|
||||
url = Utils.trim(base.endpoint, { suffix = "/" })
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local Utils = require "avante.utils"
|
||||
local Clipboard = require "avante.clipboard"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local Clipboard = require("avante.clipboard")
|
||||
local P = require("avante.providers")
|
||||
|
||||
---@class AvanteProviderFunctor
|
||||
local M = {}
|
||||
@@ -65,7 +65,7 @@ M.parse_curl_args = function(provider, prompt_opts)
|
||||
["anthropic-version"] = "2023-06-01",
|
||||
["anthropic-beta"] = "prompt-caching-2024-07-31",
|
||||
}
|
||||
if not P.env.is_local "claude" then headers["x-api-key"] = provider.parse_api_key() end
|
||||
if not P.env.is_local("claude") then headers["x-api-key"] = provider.parse_api_key() end
|
||||
|
||||
local messages = M.parse_message(prompt_opts)
|
||||
|
||||
@@ -104,7 +104,7 @@ M.on_error = function(result)
|
||||
|
||||
if error_type == "insufficient_quota" then
|
||||
error_msg = "You don't have any credits or have exceeded your quota. Please check your plan and billing details."
|
||||
elseif error_type == "invalid_request_error" and error_msg:match "temperature" then
|
||||
elseif error_type == "invalid_request_error" and error_msg:match("temperature") then
|
||||
error_msg = "Invalid temperature value. Please ensure it's between 0 and 1."
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
|
||||
---@alias CohereFinishReason "COMPLETE" | "LENGTH" | "ERROR"
|
||||
---
|
||||
@@ -69,7 +69,7 @@ M.parse_curl_args = function(provider, code_opts)
|
||||
.. "."
|
||||
.. vim.version().patch,
|
||||
}
|
||||
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 {
|
||||
url = Utils.trim(base.endpoint, { suffix = "/" }) .. "/chat",
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
---@field xcode boolean
|
||||
---@field xcode_chat boolean
|
||||
|
||||
local curl = require "plenary.curl"
|
||||
local curl = require("plenary.curl")
|
||||
|
||||
local Config = require "avante.config"
|
||||
local Path = require "plenary.path"
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Config = require("avante.config")
|
||||
local Path = require("plenary.path")
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
local O = require("avante.providers").openai
|
||||
|
||||
local H = {}
|
||||
@@ -41,15 +41,15 @@ local H = {}
|
||||
---
|
||||
---@return string
|
||||
H.get_oauth_token = function()
|
||||
local xdg_config = vim.fn.expand "$XDG_CONFIG_HOME"
|
||||
local xdg_config = vim.fn.expand("$XDG_CONFIG_HOME")
|
||||
local os_name = Utils.get_os_name()
|
||||
---@type string
|
||||
local config_dir
|
||||
|
||||
if vim.tbl_contains({ "linux", "darwin" }, os_name) then
|
||||
config_dir = (xdg_config and vim.fn.isdirectory(xdg_config) > 0) and xdg_config or vim.fn.expand "~/.config"
|
||||
config_dir = (xdg_config and vim.fn.isdirectory(xdg_config) > 0) and xdg_config or vim.fn.expand("~/.config")
|
||||
else
|
||||
config_dir = vim.fn.expand "~/AppData/Local"
|
||||
config_dir = vim.fn.expand("~/AppData/Local")
|
||||
end
|
||||
|
||||
--- hosts.json (copilot.lua), apps.json (copilot.vim)
|
||||
@@ -67,7 +67,7 @@ H.get_oauth_token = function()
|
||||
---@type table<string, OAuthToken>
|
||||
vim.json.decode(yason:read())
|
||||
)
|
||||
:filter(function(k, _) return k:match "github.com" end)
|
||||
:filter(function(k, _) return k:match("github.com") end)
|
||||
---@param acc {oauth_token: string}
|
||||
:fold({}, function(acc, _, v)
|
||||
acc.oauth_token = v.oauth_token
|
||||
@@ -83,7 +83,7 @@ H.chat_completion_url = function(base_url) return Utils.trim(base_url, { prefix
|
||||
local M = {}
|
||||
|
||||
H.refresh_token = function()
|
||||
if not M.state then error "internal initialization error" end
|
||||
if not M.state then error("internal initialization error") end
|
||||
|
||||
if
|
||||
not M.state.github_token
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local Utils = require "avante.utils"
|
||||
local P = require "avante.providers"
|
||||
local Clipboard = require "avante.clipboard"
|
||||
local Utils = require("avante.utils")
|
||||
local P = require("avante.providers")
|
||||
local Clipboard = require("avante.clipboard")
|
||||
|
||||
---@class AvanteProviderFunctor
|
||||
local M = {}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
local api = vim.api
|
||||
|
||||
local Config = require "avante.config"
|
||||
local Utils = require "avante.utils"
|
||||
local Dressing = require "avante.ui.dressing"
|
||||
local Config = require("avante.config")
|
||||
local Utils = require("avante.utils")
|
||||
local Dressing = require("avante.ui.dressing")
|
||||
|
||||
---@class AvanteHandlerOptions: table<[string], string>
|
||||
---@field on_chunk AvanteChunkParser
|
||||
@@ -98,11 +98,11 @@ E.cache = {}
|
||||
---@return string | nil
|
||||
E.parse_envvar = function(Opts)
|
||||
local api_key_name = Opts.api_key_name
|
||||
if api_key_name == nil then error "Requires api_key_name" end
|
||||
if api_key_name == nil then error("Requires api_key_name") end
|
||||
|
||||
if E.cache[api_key_name] ~= nil then return E.cache[api_key_name] end
|
||||
|
||||
local cmd = api_key_name:match "^cmd:(.*)"
|
||||
local cmd = api_key_name:match("^cmd:(.*)")
|
||||
|
||||
local key = nil
|
||||
|
||||
@@ -173,7 +173,7 @@ E.setup = function(opts)
|
||||
opts.provider.setup()
|
||||
|
||||
-- check if var is a all caps string
|
||||
if var == M.AVANTE_INTERNAL_KEY or var:match "^cmd:(.*)" then return end
|
||||
if var == M.AVANTE_INTERNAL_KEY or var:match("^cmd:(.*)") then return end
|
||||
|
||||
local refresh = opts.refresh or false
|
||||
|
||||
@@ -208,10 +208,10 @@ E.setup = function(opts)
|
||||
"noice",
|
||||
}
|
||||
if not vim.tbl_contains(exclude_filetypes, vim.bo.filetype) and not opts.provider.has() then
|
||||
Dressing.initialize_input_buffer {
|
||||
Dressing.initialize_input_buffer({
|
||||
opts = { prompt = "Enter " .. var .. ": " },
|
||||
on_confirm = on_confirm,
|
||||
}
|
||||
})
|
||||
end
|
||||
end, 200)
|
||||
end
|
||||
@@ -284,16 +284,16 @@ M.setup = function()
|
||||
|
||||
---@type AvanteProviderFunctor
|
||||
local provider = M[Config.provider]
|
||||
E.setup { provider = provider }
|
||||
E.setup({ provider = provider })
|
||||
end
|
||||
|
||||
---@param provider Provider
|
||||
function M.refresh(provider)
|
||||
require("avante.config").override { provider = provider }
|
||||
require("avante.config").override({ provider = provider })
|
||||
|
||||
---@type AvanteProviderFunctor
|
||||
local p = M[Config.provider]
|
||||
E.setup { provider = p, refresh = true }
|
||||
E.setup({ provider = p, refresh = true })
|
||||
Utils.info("Switch to provider: " .. provider, { once = true, title = "Avante" })
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local Utils = require "avante.utils"
|
||||
local Config = require "avante.config"
|
||||
local Clipboard = require "avante.clipboard"
|
||||
local P = require "avante.providers"
|
||||
local Utils = require("avante.utils")
|
||||
local Config = require("avante.config")
|
||||
local Clipboard = require("avante.clipboard")
|
||||
local P = require("avante.providers")
|
||||
|
||||
---@class OpenAIChatResponse
|
||||
---@field id string
|
||||
@@ -56,11 +56,11 @@ M.parse_message = function(opts)
|
||||
end
|
||||
|
||||
M.parse_response = function(data_stream, _, opts)
|
||||
if data_stream:match '"%[DONE%]":' then
|
||||
if data_stream:match('"%[DONE%]":') then
|
||||
opts.on_complete(nil)
|
||||
return
|
||||
end
|
||||
if data_stream:match '"delta":' then
|
||||
if data_stream:match('"delta":') then
|
||||
---@type OpenAIChatResponse
|
||||
local json = vim.json.decode(data_stream)
|
||||
if json.choices and json.choices[1] then
|
||||
@@ -80,7 +80,7 @@ M.parse_curl_args = function(provider, code_opts)
|
||||
local headers = {
|
||||
["Content-Type"] = "application/json",
|
||||
}
|
||||
if not P.env.is_local "openai" then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
||||
if not P.env.is_local("openai") then headers["Authorization"] = "Bearer " .. provider.parse_api_key() end
|
||||
|
||||
return {
|
||||
url = Utils.trim(base.endpoint, { suffix = "/" }) .. "/chat/completions",
|
||||
|
||||
Reference in New Issue
Block a user