@@ -475,6 +475,16 @@ function Chat:toString()
475475 return str
476476end
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+
478488function 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
494512end
@@ -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