mirror of
https://ghfast.top/https://github.com/discourse/discourse-ai.git
synced 2026-07-16 11:36:23 +08:00
This commit introduces a new Forum Researcher persona specialized in deep forum content analysis along with comprehensive improvements to our AI infrastructure.
Key additions:
New Forum Researcher persona with advanced filtering and analysis capabilities
Robust filtering system supporting tags, categories, dates, users, and keywords
LLM formatter to efficiently process and chunk research results
Infrastructure improvements:
Implemented CancelManager class to centrally manage AI completion cancellations
Replaced callback-based cancellation with a more robust pattern
Added systematic cancellation monitoring with callbacks
Other improvements:
Added configurable default_enabled flag to control which personas are enabled by default
Updated translation strings for the new researcher functionality
Added comprehensive specs for the new components
Renames Researcher -> Web Researcher
This change makes our AI platform more stable while adding powerful research capabilities that can analyze forum trends and surface relevant content.
88 lines
2.4 KiB
Ruby
88 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Personas
|
|
module Tools
|
|
class EditImage < Tool
|
|
def self.signature
|
|
{
|
|
name: name,
|
|
description: "Renders images from supplied descriptions",
|
|
parameters: [
|
|
{
|
|
name: "prompt",
|
|
description:
|
|
"instructions for the image to be edited (5000 chars or less, be creative)",
|
|
type: "string",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "image_urls",
|
|
description:
|
|
"The images to provides as context for the edit (minimum 1, maximum 10), use the short url eg: upload://qUm0DGR49PAZshIi7HxMd3cAlzn.png",
|
|
type: "array",
|
|
item_type: "string",
|
|
required: true,
|
|
},
|
|
],
|
|
}
|
|
end
|
|
|
|
def self.name
|
|
"edit_image"
|
|
end
|
|
|
|
def prompt
|
|
parameters[:prompt]
|
|
end
|
|
|
|
def chain_next_response?
|
|
!!@error
|
|
end
|
|
|
|
def image_urls
|
|
parameters[:image_urls]
|
|
end
|
|
|
|
def invoke
|
|
yield(prompt)
|
|
|
|
return { prompt: prompt, error: "No valid images provided" } if image_urls.blank?
|
|
|
|
sha1s = image_urls.map { |url| Upload.sha1_from_short_url(url) }.compact
|
|
uploads = Upload.where(sha1: sha1s).order(created_at: :asc).limit(10).to_a
|
|
|
|
return { prompt: prompt, error: "No valid images provided" } if uploads.blank?
|
|
|
|
begin
|
|
result =
|
|
DiscourseAi::Inference::OpenAiImageGenerator.create_edited_upload!(
|
|
uploads,
|
|
prompt,
|
|
user_id: bot_user.id,
|
|
cancel_manager: context.cancel_manager,
|
|
)
|
|
rescue => e
|
|
@error = e
|
|
return { prompt: prompt, error: e.message }
|
|
end
|
|
|
|
if result.blank?
|
|
@error = true
|
|
return { prompt: prompt, error: "Something went wrong, could not generate image" }
|
|
end
|
|
|
|
self.custom_raw = "![#{result[:prompt].gsub(/\|\'\"/, "")}](#{result[:upload].short_url})"
|
|
|
|
{ prompt: result[:prompt], url: result[:upload].short_url }
|
|
end
|
|
|
|
protected
|
|
|
|
def description_args
|
|
{ prompt: prompt }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|