Class TRLLMServiceProvider

Direct Known Subclasses:
AvaLLMServiceProvider, CratePackingLLMServiceProvider, PickAndPlace2024LLMServiceProvider, SpotPickAndPlaceLLMServiceProvider

public abstract class TRLLMServiceProvider extends BasicLLMServiceProvider
  • Field Details

    • language

      protected String language
    • processMatchingNLUParseLiteralsAsRefs

      protected boolean processMatchingNLUParseLiteralsAsRefs
    • learnedActionsString

      protected String learnedActionsString
    • learnedActionNames

      protected List<String> learnedActionNames
  • Constructor Details

    • TRLLMServiceProvider

      public TRLLMServiceProvider()
  • Method Details

    • getNluSystemPrompt

      protected abstract Prompt getNluSystemPrompt()
    • getNluUserPrompt

      protected abstract Prompt getNluUserPrompt()
    • getNlgSystemPrompt

      protected abstract Prompt getNlgSystemPrompt()
    • getNlgUserPrompt

      protected abstract Prompt getNlgUserPrompt()
    • getValidationSystemPrompt

      protected abstract Prompt getValidationSystemPrompt()
    • getValidationUserPrompt

      protected abstract Prompt getValidationUserPrompt()
    • populatePromptVars

      protected abstract Map<String,String> populatePromptVars(Utterance utterance, Map<String,String> promptVars, boolean system, boolean parsing, boolean validation)
      Return prompt variables relevant for the associated Prompt to be included in an upcoming request. Refer to the Prompt class and apply method if this notion is unfamiliar to you. These details may be generated on each request, or constantly updated in the background and provided to requests from this method. Please explicitly incorporate, overwrite, or discard information supplied in the passed in promptVars.
      Parameters:
      utterance - - The input/output utterance associated with this request
      promptVars - - Default prompt variables containing common system information gathered in LLMServiceProvider
      system - - Whether these variables are being applied to the system message or user message
      parsing - - Whether this call is part of an NLU or NLG request
      validation - - (NLG Only) whether this call is associated with a system validation question
      Returns:
      The variables to apply to the associated prompt in an upcoming request
    • getRefTypes

      protected abstract List<String> getRefTypes()
    • correctCommonNLUMistakes

      protected abstract Utterance correctCommonNLUMistakes(Utterance utterance)
      Domain specific postprocessing on NLU completions. Simply return supplied utterance if you have no domain specific postprocessing.
    • getDescriptorType

      protected abstract String getDescriptorType(String agentName, String descriptor)
      Used during NLU postprocessing - Check if the supplied descriptor matches any known references in the system. Return the associated reference's type (the descriptor will be typed replaced with a variable to later be dereferenced) Return an empty string if no match is found or you do not desire this functionality.
    • init

      protected void init()
      Description copied from class: DiarcComponent
      Perform any component initialization. This should not be used for setting local fields to default values as was the case in DIARC. This method is called after the constructor, and after parseArgs. Setting default values should be done in field declaration or in the constructor.
      Overrides:
      init in class LLMServiceProvider
    • generateNLUChat

      protected Chat generateNLUChat(Utterance utterance)
      Description copied from class: BasicLLMServiceProvider
      Generate a Chat object to call LLM's chatCompletion service with for the parsing task. Practically entails creating a new or updating an existing Chat object to contain the proper system, user, and assistant messages to come up with a proper parse of the supplied utterance.
      Specified by:
      generateNLUChat in class BasicLLMServiceProvider
      Parameters:
      utterance - incoming utterance to be parsed
      Returns:
      Fully updated Chat object to pass to an LLM's chatCompletion service for parsing
    • generateNLGChat

      protected Chat generateNLGChat(Utterance utterance)
      Description copied from class: BasicLLMServiceProvider
      Generate a Chat object to call LLM's chatCompletion service with for the generation task. Practically entails generating a system and user message for an NLG request of the supplied utterance.
      Specified by:
      generateNLGChat in class BasicLLMServiceProvider
      Parameters:
      utterance - outgoing utterance to perform NLG for
      Returns:
      Fully updated Chat object to pass to an LLM's chatCompletion service for NLG
    • parseNLUCompletionResponse

      public Utterance parseNLUCompletionResponse(Utterance incomingUtterance, Completion llmResponse)
      Description copied from class: BasicLLMServiceProvider
      Postprocessing of LLM's chatCompletion return value for the NLU task.
      Specified by:
      parseNLUCompletionResponse in class BasicLLMServiceProvider
      Returns:
      The fully populated Utterance to return from parseUtterance
    • processSemantics

      protected List<Symbol> processSemantics(Predicate semantics, List<Symbol> processedArguments, Map<Symbol,Variable> varMap, Utterance.Builder output, String actor)
      Return processed arguments for supplied semantics returned by Completion request - fails if any arguments are unpopulated variables - replaces values matching descriptors for entities with types defined in refTypes with variables for RR
    • parseNLGCompletionResponse

      public Utterance parseNLGCompletionResponse(Utterance outgoingUtterance, Completion llmResponse)
      Description copied from class: BasicLLMServiceProvider
      Postprocessing of LLM's chatCompletion return value for the NLG task.
      Specified by:
      parseNLGCompletionResponse in class BasicLLMServiceProvider
      Returns:
      The fully populated Utterance to return convertSemanticsToText.
    • getConversationHistoryString

      protected String getConversationHistoryString(List<Utterance> conversationHistory)
    • getCurrentGoals

      protected List<Predicate> getCurrentGoals(Symbol agent)
    • getCurrentGoalsSummary

      protected String getCurrentGoalsSummary(Symbol agent)
    • getCurrentQuestionsString

      protected String getCurrentQuestionsString(Symbol agent)
    • initLearnedActions

      protected void initLearnedActions()
      Overrides:
      initLearnedActions in class LLMServiceProvider
    • handleDatabaseAddition

      public void handleDatabaseAddition(ActionDBEntry entry) throws ai.thinkingrobots.trade.TRADEException
      Overrides:
      handleDatabaseAddition in class LLMServiceProvider
      Throws:
      ai.thinkingrobots.trade.TRADEException
    • handleDatabaseRemoval

      public void handleDatabaseRemoval(ActionDBEntry entry) throws ai.thinkingrobots.trade.TRADEException
      Overrides:
      handleDatabaseRemoval in class LLMServiceProvider
      Throws:
      ai.thinkingrobots.trade.TRADEException
    • testLLMNLGWithString

      public void testLLMNLGWithString(String semantics)