# frozen_string_literal: true module DiscourseAi module AiHelper class TopicHelper def initialize(user) @user = user end def explain(term_to_explain, post) return nil unless term_to_explain return nil unless post reply_to = post.reply_to_post topic = post.topic prompt = CompletionPrompt.enabled_by_name("explain") raise Discourse::InvalidParameters.new(:mode) if !prompt input = <<~TEXT #{term_to_explain} #{post.raw} #{topic.title} #{reply_to ? "#{reply_to.raw}" : nil} TEXT DiscourseAi::AiHelper::Assistant.new.generate_and_send_prompt(prompt, input, user) end private attr_reader :user end end end