Class LLMItemSerializer

java.lang.Object
org.openhab.core.voice.text.interpreter.llm.LLMItemSerializer

@NonNullByDefault public final class LLMItemSerializer extends Object
LLMItemSerializer is a utility class to serialize a collection of items (both semantic and non-semantic) into a structured, hierarchical string representation for passing into the context of a Large Language Model (LLM) based HumanLanguageInterpreter.

Evaluates semantic relations via MetadataRegistry (using keys like hasLocation, isPartOf, and isPointOf) with fallback to standard Group membership hierarchy. Output is formatted in a custom, token-efficient syntax.

Author:
Florian Hotze - Initial contribution
  • Method Details

    • serialize

      public static String serialize(Collection<Item> items, MetadataRegistry metadataRegistry, @Nullable Locale locale)
      Serializes a collection of items, evaluating openHAB semantic relations and group membership, localizing command options with the given locale if available.
      Parameters:
      items - the items to serialize
      metadataRegistry - the metadata registry used to query semantic relation metadata, or null
      locale - the locale to use for command options localization
      Returns:
      the serialized representation of the items