Module: ChatManager::TitleGeneratable

Extended by:
ActiveSupport::Concern
Defined in:
lib/chat_manager/title_generatable.rb

Instance Method Summary collapse

Instance Method Details

#generate_title(prompt_text, jwt_token) ⇒ Object

Generate a title for the chat by summarizing the user’s prompt. Delegates the actual summarization to ‘summarize_for_title`, which must be implemented by the including model.



10
11
12
13
14
15
16
17
# File 'lib/chat_manager/title_generatable.rb', line 10

def generate_title(prompt_text, jwt_token)
  return if title.present?

  summary = summarize_for_title(prompt_text, jwt_token)
  update!(title: summary.truncate(255)) if summary.present?
rescue StandardError => e
  Rails.logger.error "Failed to generate chat title: #{e.class} - #{e.message}"
end