mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-02-10 05:24:44 +00:00
This allows users to share a static page of an AI conversation with the rest of the world. By default this feature is disabled, it is enabled by turning on ai_bot_allow_public_sharing via site settings Precautions are taken when sharing 1. We make a carbonite copy 2. We minimize work generating page 3. We limit to 100 interactions 4. Many security checks - including disallowing if there is a mix of users in the PM. * Bonus commit, large PRs like this PR did not work with github tool large objects would destroy context Co-authored-by: Martin Brennan <martin@discourse.org>
35 lines
900 B
Ruby
35 lines
900 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class StreamPostHelper < ::Jobs::Base
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
return unless post = Post.includes(:topic).find_by(id: args[:post_id])
|
|
return unless user = User.find_by(id: args[:user_id])
|
|
return unless args[:term_to_explain]
|
|
|
|
topic = post.topic
|
|
reply_to = post.reply_to_post
|
|
|
|
return unless user.guardian.can_see?(post)
|
|
|
|
prompt = CompletionPrompt.enabled_by_name("explain")
|
|
|
|
input = <<~TEXT
|
|
<term>#{args[:term_to_explain]}</term>
|
|
<context>#{post.raw}</context>
|
|
<topic>#{topic.title}</topic>
|
|
#{reply_to ? "<replyTo>#{reply_to.raw}</replyTo>" : nil}
|
|
TEXT
|
|
|
|
DiscourseAi::AiHelper::Assistant.new.stream_prompt(
|
|
prompt,
|
|
input,
|
|
user,
|
|
"/discourse-ai/ai-helper/explain/#{post.id}",
|
|
)
|
|
end
|
|
end
|
|
end
|