Skip to content

Commit

Permalink
Merge pull request #118 from merefield/fix_web_search_with_serpapi
Browse files Browse the repository at this point in the history
FIX: web search with Serp API
  • Loading branch information
merefield authored Aug 30, 2024
2 parents b883c2b + 5b312d7 commit 866a672
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/discourse_chatbot/functions/web_search_function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def process(args)
hash_results = ::GoogleSearch.new(q: args[parameters[0][:name]], serp_api_key: SiteSetting.chatbot_serp_api_key)
.get_hash

hash_results.dig(:answer_box, :answer) ||
hash_results.dig(:answer_box, :snippet) ||
result = hash_results.dig(:organic_results, 0, :snippet)
result = hash_results.dig(:answer_box, :answer).presence ||
hash_results.dig(:answer_box, :snippet).presence ||
hash_results.dig(:organic_results)
end
result[0..SiteSetting.chatbot_function_response_char_limit]
rescue
rescue => e
Rails.logger.error("Chatbot: Error in web_search function: #{e}")
I18n.t("chatbot.prompt.function.web_search.error", query: args[parameters[0][:name]])
end
end
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: 1.0.1
# version: 1.0.2
# authors: merefield
# url: https://github.com/merefield/discourse-chatbot

Expand Down

0 comments on commit 866a672

Please sign in to comment.