Skip to content

Commit

Permalink
fix: save tiktoken file based on url
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Jul 14, 2024
1 parent ce21217 commit 6f143f2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lua/CopilotChat/tiktoken.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ local curl = require('plenary.curl')
local tiktoken_core = nil

---Get the path of the cache directory
---@param fname string
---@return string
local function get_cache_path()
return vim.fn.stdpath('cache') .. '/cl100k_base.tiktoken'
local function get_cache_path(fname)
return vim.fn.stdpath('cache') .. '/' .. fname
end

local function file_exists(name)
Expand All @@ -26,7 +27,8 @@ local function load_tiktoken_data(done, model)
end
local async
async = vim.loop.new_async(function()
local cache_path = get_cache_path()
-- Take filename after the last slash of the url
local cache_path = get_cache_path(tiktoken_url:match('.+/(.+)'))
if not file_exists(cache_path) then
curl.get(tiktoken_url, {
output = cache_path,
Expand Down

0 comments on commit 6f143f2

Please sign in to comment.