Class AiConversationAutoTitleService

java.lang.Object
io.jmix.aitoolsflowui.service.AiConversationAutoTitleService

@Component("aitls_AiConversationAutoTitleService") public class AiConversationAutoTitleService extends Object
Generates a conversation title in the background and persists it. The generated title is applied only while the conversation still carries the title it was started with, so a manual rename is not overwritten.
  • Field Details

  • Constructor Details

    • AiConversationAutoTitleService

      public AiConversationAutoTitleService()
  • Method Details

    • generateAndApplyAsync

      public void generateAndApplyAsync(UUID conversationId, String firstUserMessage, String expectedTitle, Consumer<@Nullable String> onApplied)
      Runs generateAndApply(UUID, String, String) in the background.

      Must be called from a UI thread: the task is not cancelled when the user leaves the view, and the callback runs on the UI thread.

      Parameters:
      conversationId - id of the conversation to title
      firstUserMessage - first user message the title is derived from
      expectedTitle - title the conversation must still carry for the generated title to be applied
      onApplied - receives the applied title, or null when nothing was applied
    • generateAndApply

      public @Nullable String generateAndApply(UUID conversationId, String firstUserMessage, String expectedTitle)
      Generates the title and persists it if the conversation still carries expectedTitle.
      Parameters:
      conversationId - id of the conversation to title
      firstUserMessage - first user message the title is derived from
      expectedTitle - title the conversation must still carry
      Returns:
      the applied title, or null when nothing was generated or the title changed meanwhile
    • generate

      protected @Nullable String generate(String firstUserMessage)