Package io.jmix.aichat.data
Class DefaultAiChatMessageFactory
java.lang.Object
io.jmix.aichat.data.DefaultAiChatMessageFactory
- All Implemented Interfaces:
AiChatMessageFactory<SimpleAiChatMessage>,Serializable,Function<AiChatMessageContext,SimpleAiChatMessage>
@Component("aichat_DefaultAiChatMessageFactory")
public class DefaultAiChatMessageFactory
extends Object
implements AiChatMessageFactory<SimpleAiChatMessage>
The message factory
AiChat falls back to when the application supplies none:
it mints SimpleAiChatMessage instances and saves their attachments to the
default file storage. This is the only place the add-on writes to FileStorage.
It fits the in-memory path, where the message type is SimpleAiChatMessage; an
entity-backed source supplies its own factory instead, because the message contract is
read-only and the component never creates entities itself. Replace it by declaring a
@Primary bean of a subclass: getFileStorage() chooses where attachments go,
saveAttachments(List) how they are stored, and apply(io.jmix.aichat.data.AiChatMessageContext) what message
is built from the result.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(AiChatMessageContext context) Creates a message for the given context.protected FileStorageReturns the storage the attachments are saved to.saveAttachments(List<com.vaadin.flow.component.ai.common.AIAttachment> attachments) Saves the given attachments and returns the references to them.
-
Field Details
-
fileStorageLocator
-
-
Constructor Details
-
DefaultAiChatMessageFactory
public DefaultAiChatMessageFactory()
-
-
Method Details
-
apply
Description copied from interface:AiChatMessageFactoryCreates a message for the given context. The factory owns persistence: for an entity source it saves each attachment's bytes to file storage and sets the resultingFileRefs on the created message.- Specified by:
applyin interfaceAiChatMessageFactory<SimpleAiChatMessage>- Specified by:
applyin interfaceFunction<AiChatMessageContext,SimpleAiChatMessage> - Parameters:
context- what is known about the message to create- Returns:
- the created message
-
saveAttachments
protected List<FileRef> saveAttachments(List<com.vaadin.flow.component.ai.common.AIAttachment> attachments) Saves the given attachments and returns the references to them. An empty list is stored nowhere, so no file storage is resolved for a message without attachments.- Parameters:
attachments- the files attached to the message- Returns:
- the references to the saved files, in the order the attachments were given
-
getFileStorage
Returns the storage the attachments are saved to. Override to write to a named storage instead of the application's default one.- Returns:
- the file storage
-