Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #33 from jameshiew/curl-debugging
Browse files Browse the repository at this point in the history
Release 0.3.1, add more debug logs for curl
  • Loading branch information
jameshiew authored Sep 29, 2021
2 parents dcaf406 + 730cae5 commit 3813986
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [0.3.1] - 2021-09-29

### Changed
* More logging for `curl` calls when debug logging is enabled

### Fixed
* Selections made in visual lines mode ("V") should now work (thanks @naefl for debugging)
Expand Down Expand Up @@ -55,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.1.0] - 2021-09-13

[0.3.1]: https://github.com/jameshiew/nvim-magic/compare/0.3.0...0.3.1
[0.3.0]: https://github.com/jameshiew/nvim-magic/compare/0.2.3...0.3.0
[0.2.3]: https://github.com/jameshiew/nvim-magic/compare/v0.2.2...0.2.3
[0.2.2]: https://github.com/jameshiew/nvim-magic/compare/v0.2.1...v0.2.2
Expand Down
7 changes: 5 additions & 2 deletions lua/nvim-magic-openai/_completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ function completion.new_request(prompt, max_tokens, stops)
end

function completion.extract_from(res_body)
local decoded = vim.fn.json_decode(res_body)
assert(decoded ~= nil, "couldn't decode body")
local ok, decoded = pcall(vim.fn.json_decode, res_body)
if not ok then
local errmsg = decoded
error(string.format("couldn't decode response body errmsg=%s body=%s", errmsg, res_body))
end
assert(decoded.choices ~= nil, 'no choices returned')
return decoded.choices[1].text
end
Expand Down
24 changes: 20 additions & 4 deletions lua/nvim-magic-openai/_curl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ local F = require('plenary.functional')
local J = require('plenary.job')
local P = require('plenary.path')

local log = require('nvim-magic-openai._log')

local DEFAULT_TIMEOUT = 10000 -- milliseconds

local function is_windows()
Expand Down Expand Up @@ -230,7 +232,8 @@ parse.request = function(opts)
opts.raw_body = b
end
end
return vim.tbl_flatten({

local preargs = vim.tbl_flatten({
'-sSL',
opts.dump,
opts.compressed and '--compressed' or nil,
Expand All @@ -241,12 +244,25 @@ parse.request = function(opts)
parse.data_body(opts.data),
parse.form(opts.form),
parse.file(opts.in_file),
parse.auth(opts.auth),
})
local postargs = vim.tbl_flatten({
opts.raw,
opts.output and { '-o', opts.output } or nil,
parse.url(opts.url, opts.query),
}),
opts
})
local nonauth_args = vim.deepcopy(preargs)
vim.list_extend(nonauth_args, postargs)
log.fmt_debug('Parsed request options nonauth_curl_args=%s', nonauth_args)

local args = preargs
vim.list_extend(
args,
vim.tbl_flatten({
parse.auth(opts.auth),
})
)
vim.list_extend(args, postargs)
return preargs, opts
end

-- Parse response ------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-magic-openai/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local function default_config()
end

function openai.version()
return '0.3.1-dev'
return '0.3.1'
end

function openai.new(override)
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-magic/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local function default_config()
end

function magic.version()
return '0.3.1-dev'
return '0.3.1'
end

function magic.setup(override)
Expand Down

0 comments on commit 3813986

Please sign in to comment.