# frozen_string_literal: true module DiscourseAi module AiHelper class ChatThreadTitler def initialize(thread) @thread = thread end def suggested_title @thread.then { thread_content(_1) }.then { call_llm(_1) }.then { cleanup(_1) } end def call_llm(thread_content) return nil if thread_content.blank? 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