Skip to content

Commit 81e772d

Browse files
authored
Merge branch 'jackMort:main' into main
2 parents e93ba58 + f189c51 commit 81e772d

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

lua/chatgpt/code_edits.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,12 @@ M.edit_with_instructions = function(output_lines, bufnr, selection, ...)
310310
for _, winid in ipairs({ input_window.winid, output_window.winid }) do
311311
vim.api.nvim_set_current_win(winid)
312312
if diff_mode then
313+
-- set local wrap to be previous option to make it mroe readable(wrap=true is often more readable in diff mode).
314+
local previous_wrap = vim.o.wrap
313315
vim.api.nvim_command("diffthis")
316+
if vim.o.wrap ~= previous_wrap then
317+
vim.o.wrap = previous_wrap
318+
end
314319
else
315320
vim.api.nvim_command("diffoff")
316321
end

lua/chatgpt/flows/chat/base.lua

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ function Chat:toString()
475475
return str
476476
end
477477

478+
local function createContent(line)
479+
local extensions = { "%.jpeg", "%.jpg", "%.png", "%.gif", "%.bmp", "%.tif", "%.tiff", "%.webp" }
480+
for _, ext in ipairs(extensions) do
481+
if string.find(line:lower(), ext .. "$") then
482+
return { type = "image_url", image_url = line }
483+
end
484+
end
485+
return { type = "text", text = line }
486+
end
487+
478488
function Chat:toMessages()
479489
local messages = {}
480490
if self.system_message ~= nil then
@@ -488,7 +498,15 @@ function Chat:toMessages()
488498
elseif msg.type == ANSWER then
489499
role = "assistant"
490500
end
491-
table.insert(messages, { role = role, content = msg.text })
501+
local content = {}
502+
if self.params.model == "gpt-4-vision-preview" then
503+
for _, line in ipairs(msg.lines) do
504+
table.insert(content, createContent(line))
505+
end
506+
else
507+
content = msg.text
508+
end
509+
table.insert(messages, { role = role, content = content })
492510
end
493511
return messages
494512
end
@@ -656,14 +674,17 @@ function Chat:get_layout_params()
656674

657675
local box = Layout.Box({
658676
left_layout,
659-
Layout.Box(self.chat_input, { size = 2 + self.prompt_lines }),
677+
Layout.Box(self.chat_input, { size = (self.chat_input.border._.style == "none" and 0 or 2) + self.prompt_lines }),
660678
}, { dir = "col" })
661679

662680
if self.settings_open then
663681
box = Layout.Box({
664682
Layout.Box({
665683
left_layout,
666-
Layout.Box(self.chat_input, { size = 2 + self.prompt_lines }),
684+
Layout.Box(
685+
self.chat_input,
686+
{ size = (self.chat_input.border._.style == "none" and 0 or 2) + self.prompt_lines }
687+
),
667688
}, { dir = "col", grow = 1 }),
668689
Layout.Box({
669690
Layout.Box(self.settings_panel, { size = "30%" }),

0 commit comments

Comments
 (0)