Sam c34fcc8a95
FEATURE: forum researcher persona for deep research (#1313)
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.
2025-05-14 12:36:16 +10:00

63 lines
1.6 KiB
Ruby

# frozen_string_literal: true
module DiscourseAi
module Personas
module ArtifactUpdateStrategies
class InvalidFormatError < StandardError
end
class Base
attr_reader :post, :user, :artifact, :artifact_version, :instructions, :llm, :cancel_manager
def initialize(
llm:,
post:,
user:,
artifact:,
artifact_version:,
instructions:,
cancel_manager: nil
)
@llm = llm
@post = post
@user = user
@artifact = artifact
@artifact_version = artifact_version
@instructions = instructions
@cancel_manager = cancel_manager
end
def apply(&progress)
changes = generate_changes(&progress)
parsed_changes = parse_changes(changes)
apply_changes(parsed_changes)
end
private
def generate_changes(&progress)
response = +""
llm.generate(build_prompt, user: user, cancel_manager: cancel_manager) do |partial|
progress.call(partial) if progress
response << partial
end
response
end
def build_prompt
# To be implemented by subclasses
raise NotImplementedError
end
def parse_changes(response)
# To be implemented by subclasses
raise NotImplementedError
end
def apply_changes(changes)
# To be implemented by subclasses
raise NotImplementedError
end
end
end
end
end