feat(tiktoken): automatic build (#9)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
@@ -3,6 +3,7 @@ local sidebar = require("avante.sidebar")
|
||||
local config = require("avante.config")
|
||||
|
||||
function M.setup(opts)
|
||||
require("tiktoken_lib").load()
|
||||
config.update(opts)
|
||||
sidebar.setup()
|
||||
end
|
||||
|
||||
29
lua/tiktoken_lib.lua
Normal file
29
lua/tiktoken_lib.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
local H = {}
|
||||
local M = {}
|
||||
|
||||
H.get_os_name = function()
|
||||
local os_name = vim.loop.os_uname().sysname
|
||||
if os_name == "Linux" then
|
||||
return "linux"
|
||||
elseif os_name == "Darwin" then
|
||||
return "macOS"
|
||||
else
|
||||
error("Unsupported operating system: " .. os_name)
|
||||
end
|
||||
end
|
||||
|
||||
H.library_path = function()
|
||||
local os_name = H.get_os_name()
|
||||
local ext = os_name == "linux" and "so" or "dylib"
|
||||
local dirname = string.sub(debug.getinfo(1).source, 2, #"/tiktoken_lib.lua" * -1)
|
||||
return dirname .. ("../build/?.%s"):format(ext)
|
||||
end
|
||||
|
||||
M.load = function()
|
||||
local library_path = H.library_path()
|
||||
if not string.find(package.cpath, library_path, 1, true) then
|
||||
package.cpath = package.cpath .. ";" .. library_path
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user