Package com.tnsai.events
Record Class TextDeltaEvent
java.lang.Object
java.lang.Record
com.tnsai.events.TextDeltaEvent
- Record Components:
eventId- unique identifier for this eventtimestamp- when the event occurredmessageId- identifier for the complete message this chunk belongs tocontent- the text chunk contentrole- the message role (typically "assistant")isFinal- true if this is the final chunk of the message
- All Implemented Interfaces:
TnsAIEvent
public record TextDeltaEvent(String eventId, Instant timestamp, String messageId, String content, String role, boolean isFinal)
extends Record
implements TnsAIEvent
Event representing a streaming text chunk from the LLM.
TextDeltaEvent is emitted during streaming responses, allowing real-time display of generated text.
Example usage for real-time display:
agent.chatWithEvents("Tell me a story")
.subscribe(event -> {
if (event instanceof TextDeltaEvent delta) {
System.out.print(delta.content());
System.out.flush();
}
});
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncontent()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.eventId()Returns the value of theeventIdrecord component.static TextDeltaEventfinalChunk(String messageId, String content) Creates a final text delta event.final inthashCode()Returns a hash code value for this object.booleanisFinal()Returns the value of theisFinalrecord component.Returns the value of themessageIdrecord component.static TextDeltaEventCreates a text delta event for an assistant message.static TextDeltaEventCreates a text delta event with custom role.role()Returns the value of therolerecord component.Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.Methods inherited from interface com.tnsai.events.TnsAIEvent
eventType
-
Constructor Details
-
TextDeltaEvent
public TextDeltaEvent(String eventId, Instant timestamp, String messageId, String content, String role, boolean isFinal) Creates an instance of aTextDeltaEventrecord class.- Parameters:
eventId- the value for theeventIdrecord componenttimestamp- the value for thetimestamprecord componentmessageId- the value for themessageIdrecord componentcontent- the value for thecontentrecord componentrole- the value for therolerecord componentisFinal- the value for theisFinalrecord component
-
-
Method Details
-
of
Creates a text delta event for an assistant message.- Parameters:
messageId- the message identifiercontent- the text chunk- Returns:
- new TextDeltaEvent
-
finalChunk
Creates a final text delta event.- Parameters:
messageId- the message identifiercontent- the final text chunk- Returns:
- new TextDeltaEvent with isFinal=true
-
of
Creates a text delta event with custom role.- Parameters:
messageId- the message identifiercontent- the text chunkrole- the message role- Returns:
- new TextDeltaEvent
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
eventId
Returns the value of theeventIdrecord component.- Specified by:
eventIdin interfaceTnsAIEvent- Returns:
- the value of the
eventIdrecord component
-
timestamp
Returns the value of thetimestamprecord component.- Specified by:
timestampin interfaceTnsAIEvent- Returns:
- the value of the
timestamprecord component
-
messageId
Returns the value of themessageIdrecord component.- Returns:
- the value of the
messageIdrecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
role
Returns the value of therolerecord component.- Returns:
- the value of the
rolerecord component
-
isFinal
public boolean isFinal()Returns the value of theisFinalrecord component.- Returns:
- the value of the
isFinalrecord component
-