feat(openai): support pasting image from clipboard (#280)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-08-27 07:06:20 -04:00 committed by GitHub
parent cf68572494
commit 971e61b2c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
local Utils = require("avante.utils")
local Config = require("avante.config")
local Clipboard = require("avante.clipboard")
local P = require("avante.providers")
---@class OpenAIChatResponse
@ -55,9 +56,21 @@ M.parse_message = function(opts)
.. opts.question
end
local user_content = {}
if Config.behaviour.support_paste_from_clipboard and Clipboard.has_content() then
table.insert(user_content, {
type = "image_url",
image_url = {
url = "data:image/png;base64," .. Clipboard.get_content(),
},
})
end
table.insert(user_content, { type = "text", text = user_prompt })
return {
{ role = "system", content = opts.system_prompt },
{ role = "user", content = user_prompt },
{ role = "user", content = user_content },
}
end