From 19bf5798db80db8aced74c2b2269ca5f6dce1336 Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 19 Jun 2024 21:06:01 +0100 Subject: [PATCH] FIX: improve url identification for paint function response --- lib/discourse_chatbot/bots/open_ai_bot_rag.rb | 11 ++++++++++- plugin.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/discourse_chatbot/bots/open_ai_bot_rag.rb b/lib/discourse_chatbot/bots/open_ai_bot_rag.rb index c0cb7c5..6752192 100644 --- a/lib/discourse_chatbot/bots/open_ai_bot_rag.rb +++ b/lib/discourse_chatbot/bots/open_ai_bot_rag.rb @@ -313,7 +313,16 @@ def legal_urls?(res, post_ids_found, topic_ids_found) private - def image_url?(url) + def image_url?(string) + # Regular expression to find URLs + url_regex = /\bhttps?:\/\/[^\s]+/ + + # Check if the string contains more than one URL or other text + urls = string.scan(url_regex) + return false unless urls.length == 1 && string.strip == urls[0] + + # Proceed with the existing logic if only one URL is found + url = urls[0] image_extensions = %w[.jpg .jpeg .png .gif .bmp .tiff .webp] uri = URI.parse(url) diff --git a/plugin.rb b/plugin.rb index aa40446..f95ae57 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-chatbot # about: a plugin that allows you to have a conversation with a configurable chatbot in Discourse Chat, Topics and Private Messages -# version: 0.9.35 +# version: 0.9.36 # authors: merefield # url: https://github.com/merefield/discourse-chatbot