Skip to content

Commit 3b7d47e

Browse files
authored
fix: Use temp files when making curl requests (#179)
1 parent c1b378a commit 3b7d47e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lua/CopilotChat/copilot.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,13 @@ function Copilot:ask(prompt, opts)
369369
local full_response = ''
370370

371371
self.current_job_on_cancel = on_done
372+
373+
local temp_file = vim.fn.tempname()
374+
vim.fn.writefile({ body }, temp_file)
372375
self.current_job = curl
373376
.post(url, {
374377
headers = headers,
375-
body = body,
378+
body = temp_file,
376379
proxy = self.proxy,
377380
insecure = self.allow_insecure,
378381
on_error = function(err)
@@ -423,7 +426,7 @@ function Copilot:ask(prompt, opts)
423426
})
424427

425428
if not ok then
426-
err = 'Failed parse response: ' .. vim.inspect(content)
429+
err = 'Failed parse response: \n' .. line .. '\n' .. vim.inspect(content)
427430
log.error(err)
428431
return
429432
end
@@ -484,9 +487,12 @@ function Copilot:embed(inputs, opts)
484487
local body = vim.json.encode(generate_embedding_request(chunk, model))
485488

486489
table.insert(jobs, function(resolve)
490+
local temp_file = vim.fn.tempname()
491+
vim.fn.writefile({ body }, temp_file)
492+
487493
curl.post(url, {
488494
headers = headers,
489-
body = body,
495+
body = temp_file,
490496
proxy = self.proxy,
491497
insecure = self.allow_insecure,
492498
on_error = function(err)

0 commit comments

Comments
 (0)