mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-05-15 12:59:41 +00:00
This change-set connects GPT based chat with the forum it runs on. Allowing it to perform search, lookup tags and categories and summarize topics. The integration is currently restricted to public portions of the forum. Changes made: - Do not run ai reply job for small actions - Improved composable system prompt - Trivial summarizer for topics - Image generator - Google command for searching via Google - Corrected trimming of posts raw (was replacing with numbers) - Bypass of problem specs The feature works best with GPT-4 --------- Co-authored-by: Roman Rizzi <rizziromanalejandro@gmail.com>
53 lines
1.1 KiB
Ruby
53 lines
1.1 KiB
Ruby
#frozen_string_literal: true
|
|
|
|
module DiscourseAi::AiBot::Commands
|
|
class ImageCommand < Command
|
|
class << self
|
|
def name
|
|
"image"
|
|
end
|
|
|
|
def desc
|
|
"!image DESC - renders an image from the description (remove all connector words, keep it to 40 words or less)"
|
|
end
|
|
end
|
|
|
|
def result_name
|
|
"results"
|
|
end
|
|
|
|
def description_args
|
|
{ prompt: @last_prompt || 0 }
|
|
end
|
|
|
|
def custom_raw
|
|
@last_custom_raw
|
|
end
|
|
|
|
def chain_next_response
|
|
false
|
|
end
|
|
|
|
def process(prompt)
|
|
@last_prompt = prompt
|
|
results = DiscourseAi::Inference::StabilityGenerator.perform!(prompt)
|
|
|
|
uploads = []
|
|
|
|
results[:artifacts].each_with_index do |image, i|
|
|
f = Tempfile.new("v1_txt2img_#{i}.png")
|
|
f.binmode
|
|
f.write(Base64.decode64(image[:base64]))
|
|
f.rewind
|
|
uploads << UploadCreator.new(f, "image.png").create_for(bot_user.id)
|
|
f.unlink
|
|
end
|
|
|
|
@last_custom_raw =
|
|
uploads
|
|
.map { |upload| "" }
|
|
.join(" ")
|
|
end
|
|
end
|
|
end
|