Class LLMServiceProvider

java.lang.Object
edu.tufts.hrilab.diarc.DiarcComponent
edu.tufts.hrilab.llm.hf.LLMServiceProvider
All Implemented Interfaces:
NLGInterface
Direct Known Subclasses:
SpotPickAndPlaceLLMServiceProvider

public abstract class LLMServiceProvider extends DiarcComponent implements NLGInterface
  • Constructor Details

    • LLMServiceProvider

      public LLMServiceProvider()
  • Method Details

    • generateNLGChat

      protected abstract Chat generateNLGChat(Utterance utterance, List<Utterance> conversationHistory)
      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.
      Parameters:
      utterance - outgoing utterance to perform NLG for
      conversationHistory - Relevant dialogue history leading up to this outgoing utterance which may provide context.
      Returns:
      Fully updated Chat object to pass to an LLM's chatCompletion service for NLG
    • generateNLUChat

      protected abstract Chat generateNLUChat(Utterance utterance, Chat currentChat, List<Utterance> conversationHistory)
      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.
      Parameters:
      utterance - incoming utterance to be parsed
      currentChat - Chat object containing prior requests and responses between the LLM for this current parse attempt. Null if this is the first interaction.
      conversationHistory - Relevant dialogue history leading up to this incoming utterance which may provide context.
      Returns:
      Fully updated Chat object to pass to an LLM's chatCompletion service for parsing
    • parseNLUCompletionResponse

      protected abstract Utterance parseNLUCompletionResponse(Utterance incomingUtterance, Completion llmResponse)
      Postprocessing of LLM's chatCompletion return value for the NLU task.
      Returns:
      The fully populated Utterance to return from parseUtterance
    • parseNLGCompletionResponse

      protected abstract Utterance parseNLGCompletionResponse(Utterance outgoingUtterance, Completion llmResponse)
      Postprocessing of LLM's chatCompletion return value for the NLG task.
      Returns:
      The fully populated Utterance to return convertSemanticsToText.
    • 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 DiarcComponent
    • executionLoop

      protected void executionLoop()
      Description copied from class: DiarcComponent
      This is where any code that needs to be called repeatedly in a dedicated thread should live. It is not called by default and you must set shouldRunExecutionLoop to true in your constructor.
      Overrides:
      executionLoop in class DiarcComponent
    • convertSemanticsToText

      public Utterance convertSemanticsToText(Utterance u)
      Specified by:
      convertSemanticsToText in interface NLGInterface
    • parseUtterance

      public Utterance parseUtterance(Utterance utterance)
    • llmGenerationService

      public Utterance llmGenerationService(Utterance utterance)
    • updateLLMConversationHistory

      public void updateLLMConversationHistory(Utterance utterance)
    • startLLMConversation

      public List<Utterance> startLLMConversation(Symbol speaker, Symbol agentTeam)
      Start shared dialogue history between a user and an AgentTeam
    • startLLMConversation

      public List<Utterance> startLLMConversation(Set<Symbol> speakers, Set<Symbol> agentTeams)
      Start a shared dialogue history between a set of users and a set of AgentTeams
    • startLLMConversation

      public List<Utterance> startLLMConversation(Set<Symbol> members)
      Start shared dialogue history between a set of entities
    • endLLMConversation

      public void endLLMConversation(Symbol speaker, Symbol agentTeam)
      End shared dialogue history between a user and an AgentTeam
    • endLLMConversation

      public void endLLMConversation(Set<Symbol> speakers, Set<Symbol> agentTeams)
      End a shared dialogue history between a set of users and a set of AgentTeams
    • endLLMConversation

      public void endLLMConversation(Set<Symbol> members)
      End shared dialogue history between a set of entities
    • endLLMConversation

      public void endLLMConversation(Set<Symbol> members, Integer id)
    • startLLMChatContext

      public void startLLMChatContext(Utterance u)
    • endLLMChatContext

      public void endLLMChatContext(org.apache.commons.lang3.tuple.Pair<Symbol,Symbol> members)
    • getDescendants

      protected Set<Symbol> getDescendants(Symbol agentTeam)
    • getUntypedSymbol

      protected Symbol getUntypedSymbol(Symbol s)
    • clearConversationHistory

      public void clearConversationHistory()
    • toggleLLMNLG

      public void toggleLLMNLG()