# frozen_string_literal: true module DiscourseAi module AiHelper class ChatThreadTitler def initialize(thread) @thread = thread end def suggested_title content = thread_content(@thread) return nil if content.blank? suggested_title = call_llm(content) cleanup(suggested_title) end def call_llm(thread_content) chat = "\n#{thread_content}\n" prompt = DiscourseAi::Completions::Prompt.new( <<~TEXT.strip, I want you to act as a title generator for chat between users. I will provide you with the chat transcription, and you will generate a single attention-grabbing title. Please keep the title concise and under 15 words and ensure that the meaning is maintained. The title will utilize the same language type of the chat. I want you to only reply the suggested title and nothing else, do not write explanations. You will find the chat between XML tags. Return the suggested title between