Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions lua/CopilotChat/copilot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ local function uuid()
)
end

local function file_write(path, data, mode)
mode = mode or 'w' -- Default mode is write, which overwrites the file
local file, err = io.open(path, mode)
if not file then
error('Error opening file: ' .. tostring(err))
end
file:write(data)
file:close()
end

local function machine_id()
local length = 65
local hex_chars = '0123456789abcdef'
Expand Down Expand Up @@ -370,8 +380,8 @@ function Copilot:ask(prompt, opts)

self.current_job_on_cancel = on_done

local temp_file = vim.fn.tempname()
vim.fn.writefile({ body }, temp_file)
local temp_file = os.tmpname()
file_write(temp_file, body)
self.current_job = curl
.post(url, {
headers = headers,
Expand Down Expand Up @@ -487,8 +497,8 @@ function Copilot:embed(inputs, opts)
local body = vim.json.encode(generate_embedding_request(chunk, model))

table.insert(jobs, function(resolve)
local temp_file = vim.fn.tempname()
vim.fn.writefile({ body }, temp_file)
local temp_file = os.tmpname()
file_write(temp_file, body)

curl.post(url, {
headers = headers,
Expand Down