Class DefaultChatGenerationMetadata
java.lang.Object
org.springframework.ai.chat.metadata.DefaultChatGenerationMetadata
- All Implemented Interfaces:
ChatGenerationMetadata,ResultMetadata
Default implementation of
ChatGenerationMetadata.- Since:
- 1.0.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.ai.chat.metadata.ChatGenerationMetadata
ChatGenerationMetadata.Builder -
Field Summary
Fields inherited from interface org.springframework.ai.chat.metadata.ChatGenerationMetadata
NULL -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(String key) entrySet()boolean<T> @Nullable T@Nullable StringGet the reason this generation finished, as the provider names it.Return the normalized category of the finish reason, which is the same for every provider, whileChatGenerationMetadata.getFinishReason()keeps the name the provider uses.<T> TgetOrDefault(String key, T defaultObject) inthashCode()booleanisEmpty()keySet()toString()
-
Method Details
-
get
- Specified by:
getin interfaceChatGenerationMetadata
-
containsKey
- Specified by:
containsKeyin interfaceChatGenerationMetadata
-
getOrDefault
- Specified by:
getOrDefaultin interfaceChatGenerationMetadata
-
entrySet
- Specified by:
entrySetin interfaceChatGenerationMetadata
-
keySet
- Specified by:
keySetin interfaceChatGenerationMetadata
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceChatGenerationMetadata
-
getFinishReason
Description copied from interface:ChatGenerationMetadataGet the reason this generation finished, as the provider names it. The names differ between providers:stop,end_turnandSTOPall say that the model finished its answer. For a meaning that is the same for every provider, seeChatGenerationMetadata.getFinishReasonCategory().- Specified by:
getFinishReasonin interfaceChatGenerationMetadata- Returns:
- the raw finish reason of the provider, or
nullwhen it gave none
-
getFinishReasonCategory
Description copied from interface:ChatGenerationMetadataReturn the normalized category of the finish reason, which is the same for every provider, whileChatGenerationMetadata.getFinishReason()keeps the name the provider uses.A chat model classifies its own finish reasons and sets the category with
ChatGenerationMetadata.Builder.finishReasonCategory(FinishReasonCategory). It sees the whole provider response, so it can also classify a stop that the finish reason alone does not tell, such as a refusal reported in another field.This default implementation is the fallback for metadata that carries no category. It classifies the raw string only: a
nullreason isFinishReasonCategory.UNSPECIFIEDand an unrecognized non-blank reason isFinishReasonCategory.OTHER.- Specified by:
getFinishReasonCategoryin interfaceChatGenerationMetadata- Returns:
- the categorized finish reason, never
null - See Also:
-
getContentFilters
- Specified by:
getContentFiltersin interfaceChatGenerationMetadata
-
hashCode
public int hashCode() -
equals
-
toString
-