Skip to content

Commit

Permalink
feat(chat): enable support for gpt 4 vision api (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
e2r2fx authored Dec 13, 2023
1 parent b50fdaf commit fc0a13f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lua/chatgpt/flows/chat/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ function Chat:toString()
return str
end

local function createContent(line)
local extensions = { "%.jpeg", "%.jpg", "%.png", "%.gif", "%.bmp", "%.tif", "%.tiff", "%.webp" }
for _, ext in ipairs(extensions) do
if string.find(line:lower(), ext .. "$") then
return { type = "image_url", image_url = line }
end
end
return { type = "text", text = line }
end

function Chat:toMessages()
local messages = {}
if self.system_message ~= nil then
Expand All @@ -488,7 +498,15 @@ function Chat:toMessages()
elseif msg.type == ANSWER then
role = "assistant"
end
table.insert(messages, { role = role, content = msg.text })
local content = {}
if self.params.model == "gpt-4-vision-preview" then
for _, line in ipairs(msg.lines) do
table.insert(content, createContent(line))
end
else
content = msg.text
end
table.insert(messages, { role = role, content = content })
end
return messages
end
Expand Down

0 comments on commit fc0a13f

Please sign in to comment.