Class AssistantConversationService
java.lang.Object
ch.tocco.nice2.optional.aiassistant.impl.conversation.AssistantConversationService
Stores assistant conversations per user (tagged with the
function that owns them) and
adds the persisted conversation history as context to each new question. Each conversation is
isolated: only the messages of the conversation being continued are sent to the function.
The actual answer is produced by the AssistantFunction the conversation belongs to.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResponse body ofGET /nice2/rest/aiAssistant/conversations/{id}— a single conversation with all of its messages in chronological order.static final recordA single message of aAssistantConversationService.ConversationDetail. -
Constructor Summary
ConstructorsConstructorDescriptionAssistantConversationService(Context context, QueryBuilderFactory queryBuilderFactory, PrincipalService principalService, SecurityManager securityManager, EntityDefaultValueService entityDefaultValueService, DeleteService deleteService, AssistantFunctionRegistry functionRegistry, ConversationLabelService labelService) -
Method Summary
Modifier and TypeMethodDescriptionchat(AssistantRequest request) Answers a question inside a conversation.voiddeleteConversation(String conversationKey) Deletes the conversation and all of its messages.getConversation(String conversationKey) listConversations(String function)
-
Constructor Details
-
AssistantConversationService
public AssistantConversationService(Context context, QueryBuilderFactory queryBuilderFactory, PrincipalService principalService, SecurityManager securityManager, EntityDefaultValueService entityDefaultValueService, DeleteService deleteService, AssistantFunctionRegistry functionRegistry, ConversationLabelService labelService)
-
-
Method Details
-
chat
Answers a question inside a conversation. Continues the conversation referenced byAssistantRequest.conversationKey()(loading its messages as context and keeping its function), or starts a new one forAssistantRequest.function()(generating a label from the first question). Persists both the user question and the assistant answer.- Throws:
IllegalStateException- if no user is logged inResourceNotFoundException- if a conversation id is given that the user does not ownIllegalArgumentException- if the requested function is unknownAiAssistantException- if the function fails (nothing is persisted then)
-
listConversations
- Parameters:
function- the assistant function to list conversations for- Returns:
- the current user's conversations for that function, newest first
-
getConversation
- Returns:
- the conversation with all of its messages, oldest first
- Throws:
ResourceNotFoundException- if the user does not own a conversation with that id
-
deleteConversation
Deletes the conversation and all of its messages. Idempotent: does nothing if the current user has no conversation with that id (already deleted, never existed, or owned by someone else).
-