From 971e61b2c872e79c73cdfbbf62c750afaa4d40cb Mon Sep 17 00:00:00 2001 From: Aaron Pham Date: Tue, 27 Aug 2024 07:06:20 -0400 Subject: [PATCH] feat(openai): support pasting image from clipboard (#280) Signed-off-by: Aaron Pham --- lua/avante/providers/openai.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lua/avante/providers/openai.lua b/lua/avante/providers/openai.lua index c362b17..4076ecf 100644 --- a/lua/avante/providers/openai.lua +++ b/lua/avante/providers/openai.lua @@ -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