Class MutableResponseMetadata

java.lang.Object
org.springframework.ai.model.MutableResponseMetadata
All Implemented Interfaces:
ResponseMetadata
Direct Known Subclasses:
AudioTranscriptionResponseMetadata, ImageResponseMetadata, OpenAiAudioSpeechResponseMetadata

public class MutableResponseMetadata extends Object implements ResponseMetadata
  • Constructor Details

    • MutableResponseMetadata

      public MutableResponseMetadata()
  • Method Details

    • put

      public <T> MutableResponseMetadata put(String key, T object)
      Puts an element to the context.
      Type Parameters:
      T - value type
      Parameters:
      key - key
      object - value
      Returns:
      this for chaining
    • get

      @Nullable public <T> T get(String key)
      Gets an entry from the context. Returns null when entry is not present.
      Specified by:
      get in interface ResponseMetadata
      Type Parameters:
      T - value type
      Parameters:
      key - key
      Returns:
      entry or null if not present
    • remove

      public Object remove(Object key)
      Removes an entry from the context.
      Parameters:
      key - key by which to remove an entry
      Returns:
      the previous value associated with the key, or null if there was no mapping for the key
    • getRequired

      @NonNull public <T> T getRequired(Object key)
      Gets an entry from the context. Throws exception when entry is not present.
      Specified by:
      getRequired in interface ResponseMetadata
      Type Parameters:
      T - value type
      Parameters:
      key - key
      Returns:
      entry
      Throws:
      IllegalArgumentException - if not present
    • containsKey

      public boolean containsKey(Object key)
      Checks if context contains a key.
      Specified by:
      containsKey in interface ResponseMetadata
      Parameters:
      key - key
      Returns:
      true when the context contains the entry with the given key
    • getOrDefault

      public <T> T getOrDefault(Object key, T defaultObject)
      Returns an element or default if not present.
      Specified by:
      getOrDefault in interface ResponseMetadata
      Type Parameters:
      T - value type
      Parameters:
      key - key
      defaultObject - default object to return
      Returns:
      object or default if not present
    • entrySet

      public Set<Map.Entry<String,Object>> entrySet()
      Specified by:
      entrySet in interface ResponseMetadata
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface ResponseMetadata
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ResponseMetadata
      Returns true if this map contains no key-value mappings.
      Specified by:
      isEmpty in interface ResponseMetadata
      Returns:
      true if this map contains no key-value mappings
    • computeIfAbsent

      public <T> T computeIfAbsent(String key, Function<Object,? extends T> mappingFunction)
      Returns an element or calls a mapping function if entry not present. The function will insert the value to the map.
      Type Parameters:
      T - value type
      Parameters:
      key - key
      mappingFunction - mapping function
      Returns:
      object or one derived from the mapping function if not present
    • clear

      public void clear()
      Clears the entries from the context.
    • getRawMap

      public Map<String,Object> getRawMap()