
* feat: autobuild tiktoken lib and schenanigans Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: revert readme changes Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * fix(build): windows Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz> * chore(plugin): early load commands and base setup Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * fix(build): make sync Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * feat: rust go vroom vroom Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * feat: scuffed afaf implementation binding go brrrr Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: remove dups Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * fix(tokens): calculate whether we should do prompt_caching (fixes #416) Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: ignore lockfiles Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * Update README.md * Update crates/avante-tokenizers/README.md * chore: remove unused Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: remove auto build Signed-off-by: Aaron Pham <contact@aarnphm.xyz> --------- Signed-off-by: Aaron Pham <contact@aarnphm.xyz> Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz> Co-authored-by: yuchanns <me@yuchanns.xyz>
85 lines
2.0 KiB
Lua
85 lines
2.0 KiB
Lua
local Utils = require("avante.utils")
|
|
local P = require("avante.providers")
|
|
local Clipboard = require("avante.clipboard")
|
|
|
|
---@class AvanteProviderFunctor
|
|
local M = {}
|
|
|
|
M.api_key_name = "GEMINI_API_KEY"
|
|
M.tokenizer_id = "google/gemma-2b"
|
|
|
|
M.parse_message = function(opts)
|
|
local message_content = {}
|
|
|
|
if Clipboard.support_paste_image() and opts.image_paths then
|
|
for _, image_path in ipairs(opts.image_paths) do
|
|
local image_data = {
|
|
inline_data = {
|
|
mime_type = "image/png",
|
|
data = Clipboard.get_base64_content(image_path),
|
|
},
|
|
}
|
|
|
|
table.insert(message_content, image_data)
|
|
end
|
|
end
|
|
|
|
-- insert a part into parts
|
|
for _, user_prompt in ipairs(opts.user_prompts) do
|
|
table.insert(message_content, {
|
|
text = user_prompt,
|
|
})
|
|
end
|
|
|
|
return {
|
|
systemInstruction = {
|
|
role = "user",
|
|
parts = {
|
|
{
|
|
text = opts.system_prompt,
|
|
},
|
|
},
|
|
},
|
|
contents = {
|
|
{
|
|
role = "user",
|
|
parts = message_content,
|
|
},
|
|
},
|
|
}
|
|
end
|
|
|
|
M.parse_response = function(data_stream, _, opts)
|
|
local json = vim.json.decode(data_stream)
|
|
if json.candidates and #json.candidates > 0 then
|
|
opts.on_chunk(json.candidates[1].content.parts[1].text)
|
|
end
|
|
end
|
|
|
|
M.parse_curl_args = function(provider, code_opts)
|
|
local base, body_opts = P.parse_config(provider)
|
|
|
|
body_opts = vim.tbl_deep_extend("force", body_opts, {
|
|
generationConfig = {
|
|
temperature = body_opts.temperature,
|
|
maxOutputTokens = body_opts.max_tokens,
|
|
},
|
|
})
|
|
body_opts.temperature = nil
|
|
body_opts.max_tokens = nil
|
|
|
|
return {
|
|
url = Utils.trim(base.endpoint, { suffix = "/" })
|
|
.. "/"
|
|
.. base.model
|
|
.. ":streamGenerateContent?alt=sse&key="
|
|
.. provider.parse_api_key(),
|
|
proxy = base.proxy,
|
|
insecure = base.allow_insecure,
|
|
headers = { ["Content-Type"] = "application/json" },
|
|
body = vim.tbl_deep_extend("force", {}, M.parse_message(code_opts), body_opts),
|
|
}
|
|
end
|
|
|
|
return M
|