Record Class ResponseMetadata
- Record Components:
finishReason- why the model stopped, worded as the underlying framework reports it — the vocabulary depends on both the model and the provider, see above — ornullwhen no reason was reportedtokenUsage- the token usage of the turn, ornullwhen unknown
- All Implemented Interfaces:
Serializable
LLMProvider through
LLMProvider.LLMRequest.metadataSink() when the model reports it.
The metadata describes the turn as far as the provider has observed it: when the turn contains tool-call round trips, the finish reason is the latest one observed and the token usage covers the round trips so far, as far as the underlying framework reports them. On a turn that completes normally the last published instance therefore describes the whole turn.
Finish reason vocabulary. Every model vendor words the reason
differently and keeps adding values: a turn cut off at the output limit is
"length" on OpenAI and "max_tokens" on Anthropic. Nothing
here maps those onto a fixed set of Vaadin values, because such a set goes
stale the moment a vendor adds one. Compare only against the values
documented for the model you call, and treat an unrecognized value as unknown
rather than as an error.
LangChain4JLLMProvider is a step further removed, and shows why the
mapping is left alone: LangChain4j collapses the vendor's word onto its own
five-constant FinishReason enum before Vaadin sees the response, so
the value is that constant's name and both examples above arrive as
"LENGTH". The collapsing is per integration and loses whatever it
does not recognize — an unrecognized value reaches this record as
null through its OpenAI integration and as "OTHER" through
its Anthropic one. Use SpringAILLMProvider where the application
needs the model's own word.
- Since:
- 25.3
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordToken usage of a turn. -
Constructor Summary
ConstructorsConstructorDescriptionResponseMetadata(String finishReason, ResponseMetadata.TokenUsage tokenUsage) Creates an instance of aResponseMetadatarecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.Returns the value of thefinishReasonrecord component.final inthashCode()Returns a hash code value for this object.Returns the value of thetokenUsagerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ResponseMetadata
Creates an instance of aResponseMetadatarecord class.- Parameters:
finishReason- the value for thefinishReasonrecord componenttokenUsage- the value for thetokenUsagerecord component
-
-
Method Details
-
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. All components in this record class are compared withObjects::equals(Object,Object). -
finishReason
Returns the value of thefinishReasonrecord component.- Returns:
- the value of the
finishReasonrecord component
-
tokenUsage
Returns the value of thetokenUsagerecord component.- Returns:
- the value of the
tokenUsagerecord component
-