Class NaruThinkingSegment

java.lang.Object
net.thevpc.naru.api.model.NaruThinkingSegment
All Implemented Interfaces:
Cloneable, NToElement, NCopiable

public class NaruThinkingSegment extends Object implements NToElement, NCopiable, Cloneable
One continuous stretch of model reasoning, kept separate from the visible answer on NaruMessage.

Segmented rather than one blob because reasoning is rarely contiguous: a model may think, answer, think again, and answer again. Collapsing that into a single string loses the order, so a transcript cannot show how the answer was arrived at, and a truncated session cannot tell which thought was cut short.

Immutable. Built incrementally by the stream pipeline and sealed once the segment is known to be finished.

  • Field Details

    • UNKNOWN_TOKENS

      public static final long UNKNOWN_TOKENS
      Sentinel for "the provider did not report this", distinct from a genuine zero. Matches the convention already used for cache accounting.
      See Also:
  • Constructor Details

  • Method Details

    • of

      public static NaruThinkingSegment of(NElement element)
    • toElement

      public NElement toElement()
      Specified by:
      toElement in interface NToElement
    • hasTokenCount

      public boolean hasTokenCount()
      Whether the token count is a real measurement rather than a stand-in.
    • tokenCountOrZero

      public long tokenCountOrZero()
      The token count, or 0 when unknown.

      Returns 0 rather than the sentinel for arithmetic, so summing segments cannot accidentally bill a negative number. Use hasTokenCount() when the difference between "none" and "not measured" matters.

    • copy

      public NaruThinkingSegment copy()
      Specified by:
      copy in interface NCopiable
    • clone

      protected NaruThinkingSegment clone()
      Overrides:
      clone in class Object
    • getIndex

      public int getIndex()
    • getText

      public String getText()
    • getExtraction

      public NaruThinkingExtraction getExtraction()
    • getProvider

      public String getProvider()
    • getThinkingTokens

      public long getThinkingTokens()
    • isComplete

      public boolean isComplete()
    • toString

      public String toString()
      Concatenation of this segment's reasoning, for the legacy NaruMessage.getThinking() string field.
      Overrides:
      toString in class Object