discourse/plugins/discourse-ai/lib/discord/bot/search.rb
Sam e3fae646d4
DEV: AI persona to agent migration (#38319)
Co-authored-by: Keegan George <kgeorge13@gmail.com>
2026-03-10 15:59:45 +11:00

36 lines
857 B
Ruby
Vendored

# frozen_string_literal: true
module DiscourseAi
module Discord::Bot
class Search < Base
def initialize(body)
@search = DiscourseAi::Agents::Tools::Search
super(body)
end
def handle_interaction!
results =
@search.new(
{ search_query: @query },
agent_options: {
"max_results" => 10,
},
bot_user: nil,
llm: nil,
).invoke(&Proc.new {})
formatted_results = results[:rows].map.with_index { |result, index| <<~RESULT }.join("\n")
#{index + 1}. [#{result[0]}](<#{Discourse.base_url}#{result[1]}>)
RESULT
reply = <<~REPLY
Here are the top search results for your query:
#{formatted_results}
REPLY
create_reply(reply)
end
end
end
end