Skip to content

Commit

Permalink
fix: Make tiktoken file loading async to not block vim (CopilotC-Nvim…
Browse files Browse the repository at this point in the history
  • Loading branch information
deathbeam authored Mar 13, 2024
1 parent bb2045b commit 4b2e631
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lua/CopilotChat/tiktoken.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ end

--- Load tiktoken data from cache or download it
local function load_tiktoken_data(done)
local cache_path = get_cache_path()
if file_exists(cache_path) then
done(cache_path)
return
end
local async
async = vim.loop.new_async(function()
local cache_path = get_cache_path()
if not file_exists(cache_path) then
curl.get('https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken', {
output = cache_path,
})
end

curl.get('https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken', {
output = cache_path,
callback = function()
done(cache_path)
end,
})
done(cache_path)
async:close()
end)
async:send()
end

local M = {}
Expand Down

0 comments on commit 4b2e631

Please sign in to comment.