Skip to content

Commit

Permalink
FIX: improve url identification for paint function response
Browse files Browse the repository at this point in the history
  • Loading branch information
merefield committed Jun 19, 2024
1 parent 395e9f6 commit 19bf579
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/discourse_chatbot/bots/open_ai_bot_rag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 19bf579

Please sign in to comment.