Package io.jmix.aitoolsflowui.service
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 Summary
FieldsModifier and TypeFieldDescriptionprotected AiConversationServiceprotected AiConversationTitleGeneratorprotected UiAsyncTasks -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable String@Nullable StringgenerateAndApply(UUID conversationId, String firstUserMessage, String expectedTitle) Generates the title and persists it if the conversation still carriesexpectedTitle.voidgenerateAndApplyAsync(UUID conversationId, String firstUserMessage, String expectedTitle, Consumer<@Nullable String> onApplied) RunsgenerateAndApply(UUID, String, String)in the background.
-
Field Details
-
generator
-
conversationService
-
uiAsyncTasks
-
-
Constructor Details
-
AiConversationAutoTitleService
public AiConversationAutoTitleService()
-
-
Method Details
-
generateAndApplyAsync
public void generateAndApplyAsync(UUID conversationId, String firstUserMessage, String expectedTitle, Consumer<@Nullable String> onApplied) RunsgenerateAndApply(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 titlefirstUserMessage- first user message the title is derived fromexpectedTitle- title the conversation must still carry for the generated title to be appliedonApplied- receives the applied title, ornullwhen nothing was applied
-
generateAndApply
public @Nullable String generateAndApply(UUID conversationId, String firstUserMessage, String expectedTitle) Generates the title and persists it if the conversation still carriesexpectedTitle.- Parameters:
conversationId- id of the conversation to titlefirstUserMessage- first user message the title is derived fromexpectedTitle- title the conversation must still carry- Returns:
- the applied title, or
nullwhen nothing was generated or the title changed meanwhile
-
generate
-