Record Class NaruStreamChunkData

java.lang.Object
java.lang.Record
net.thevpc.naru.api.model.NaruStreamChunkData
All Implemented Interfaces:
NaruStreamChunk

public record NaruStreamChunkData(NaruChunkKind kind, String text, int index, String provider, NaruThinkingExtraction extraction, boolean complete) extends Record implements NaruStreamChunk
The one NaruStreamChunk implementation.

Immutability is not incidental. A streaming reader hands chunks to a renderer on a transport thread while the model call accumulates the same chunks on a worker thread, so a mutable chunk could be seen half-updated by both.

  • Constructor Details

    • NaruStreamChunkData

      public NaruStreamChunkData(NaruChunkKind kind, String text, int index, String provider, NaruThinkingExtraction extraction, boolean complete)
      Creates an instance of a NaruStreamChunkData record class.
      Parameters:
      kind - the value for the kind record component
      text - the value for the text record component
      index - the value for the index record component
      provider - the value for the provider record component
      extraction - the value for the extraction record component
      complete - the value for the complete record component
  • Method Details

    • of

      public static NaruStreamChunkData of(NaruChunkKind kind, String text, int index)
    • of

      public static NaruStreamChunkData of(NaruChunkKind kind, String text, int index, String provider)
    • thinking

      public static NaruStreamChunkData thinking(String text, int index, String provider, NaruThinkingExtraction extraction, boolean complete)
    • answer

      public static NaruStreamChunkData answer(String text, int index, String provider)
    • withText

      public NaruStreamChunkData withText(String newText)
    • withIndex

      public NaruStreamChunkData withIndex(int newIndex)
    • asComplete

      public NaruStreamChunkData asComplete(boolean newComplete)
    • providerOptional

      public NOptional<String> providerOptional()
    • extractionOptional

      public NOptional<NaruThinkingExtraction> extractionOptional()
    • logMode

      public NaruLogMode logMode()
      The log mode this chunk should be rendered under, which is how a renderer that carries no styling of its own -- a browser, an HTTP client -- can still tell thinking from answer.
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • kind

      public NaruChunkKind kind()
      Returns the value of the kind record component.
      Specified by:
      kind in interface NaruStreamChunk
      Returns:
      the value of the kind record component
    • text

      public String text()
      Returns the value of the text record component.
      Specified by:
      text in interface NaruStreamChunk
      Returns:
      the value of the text record component
    • index

      public int index()
      Returns the value of the index record component.
      Specified by:
      index in interface NaruStreamChunk
      Returns:
      the value of the index record component
    • provider

      public String provider()
      Returns the value of the provider record component.
      Specified by:
      provider in interface NaruStreamChunk
      Returns:
      the value of the provider record component
    • extraction

      public NaruThinkingExtraction extraction()
      Returns the value of the extraction record component.
      Specified by:
      extraction in interface NaruStreamChunk
      Returns:
      the value of the extraction record component
    • complete

      public boolean complete()
      Returns the value of the complete record component.
      Specified by:
      complete in interface NaruStreamChunk
      Returns:
      the value of the complete record component