Class TRLLMServiceProvider
java.lang.Object
edu.tufts.hrilab.diarc.DiarcComponent
edu.tufts.hrilab.llm.LLMServiceProvider
edu.tufts.hrilab.llm.serviceproviders.BasicLLMServiceProvider
edu.tufts.hrilab.llm.serviceproviders.tr.TRLLMServiceProvider
- Direct Known Subclasses:
AvaLLMServiceProvider,CratePackingLLMServiceProvider,PickAndPlace2024LLMServiceProvider,SpotPickAndPlaceLLMServiceProvider
-
Field Summary
FieldsFields inherited from class edu.tufts.hrilab.llm.LLMServiceProvider
agentHierarchy, conversationMappings, counter, currentConversations, learnedActions, trackDialogueHistory, trackLearnedActionsFields inherited from class edu.tufts.hrilab.diarc.DiarcComponent
executionLoopCycleTime, log, shouldRunExecutionLoop -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract UtterancecorrectCommonNLUMistakes(Utterance utterance) Domain specific postprocessing on NLU completions.protected ChatgenerateNLGChat(Utterance utterance) Generate a Chat object to call LLM's chatCompletion service with for the generation task.protected ChatgenerateNLUChat(Utterance utterance) Generate a Chat object to call LLM's chatCompletion service with for the parsing task.protected StringgetConversationHistoryString(List<Utterance> conversationHistory) getCurrentGoals(Symbol agent) protected StringgetCurrentGoalsSummary(Symbol agent) protected StringgetCurrentQuestionsString(Symbol agent) protected abstract StringgetDescriptorType(String agentName, String descriptor) Used during NLU postprocessing - Check if the supplied descriptor matches any known references in the system.protected abstract Promptprotected abstract Promptprotected abstract Promptprotected abstract Promptprotected abstract Promptprotected abstract Promptvoidvoidprotected voidinit()Perform any component initialization.protected voidparseNLGCompletionResponse(Utterance outgoingUtterance, Completion llmResponse) Postprocessing of LLM's chatCompletion return value for the NLG task.parseNLUCompletionResponse(Utterance incomingUtterance, Completion llmResponse) Postprocessing of LLM's chatCompletion return value for the NLU task.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.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 RRvoidtestLLMNLGWithString(String semantics) Methods inherited from class edu.tufts.hrilab.llm.serviceproviders.BasicLLMServiceProvider
convertSemanticsToTextLLMService, convertSemanticsToTextLLMService, inExtendedParseLoop, llmChatCompletionHelper, parseUtteranceLLMService, parseUtteranceLLMServiceMethods inherited from class edu.tufts.hrilab.llm.LLMServiceProvider
callChatEndpoint, clearConversationHistory, endLLMConversation, endLLMConversation, endLLMConversation, endLLMConversation, executionLoop, getConversationHistory, getConversationHistory, getDescendants, getLLMConversationLength, getUntypedSymbol, registerForNotifications, setLanguage, shutdownComponent, startLLMConversation, startLLMConversation, startLLMConversation, updateLLMConversationHistoryMethods inherited from class edu.tufts.hrilab.diarc.DiarcComponent
additionalUsageInfo, attachShutdownHook, createInstance, createInstance, createInstance, getMyGroupConstraints, getMyGroups, getMyService, getMyServices, main, parseArgs, postRegistrationInit, shutdown
-
Field Details
-
language
-
processMatchingNLUParseLiteralsAsRefs
protected boolean processMatchingNLUParseLiteralsAsRefs -
learnedActionsString
-
learnedActionNames
-
-
Constructor Details
-
TRLLMServiceProvider
public TRLLMServiceProvider()
-
-
Method Details
-
getNluSystemPrompt
-
getNluUserPrompt
-
getNlgSystemPrompt
-
getNlgUserPrompt
-
getValidationSystemPrompt
-
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 requestpromptVars- - Default prompt variables containing common system information gathered in LLMServiceProvidersystem- - Whether these variables are being applied to the system message or user messageparsing- - Whether this call is part of an NLU or NLG requestvalidation- - (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
-
correctCommonNLUMistakes
Domain specific postprocessing on NLU completions. Simply return supplied utterance if you have no domain specific postprocessing. -
getDescriptorType
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:DiarcComponentPerform 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:
initin classLLMServiceProvider
-
generateNLUChat
Description copied from class:BasicLLMServiceProviderGenerate 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:
generateNLUChatin classBasicLLMServiceProvider- Parameters:
utterance- incoming utterance to be parsed- Returns:
- Fully updated Chat object to pass to an LLM's chatCompletion service for parsing
-
generateNLGChat
Description copied from class:BasicLLMServiceProviderGenerate 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:
generateNLGChatin classBasicLLMServiceProvider- Parameters:
utterance- outgoing utterance to perform NLG for- Returns:
- Fully updated Chat object to pass to an LLM's chatCompletion service for NLG
-
parseNLUCompletionResponse
Description copied from class:BasicLLMServiceProviderPostprocessing of LLM's chatCompletion return value for the NLU task.- Specified by:
parseNLUCompletionResponsein classBasicLLMServiceProvider- 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
Description copied from class:BasicLLMServiceProviderPostprocessing of LLM's chatCompletion return value for the NLG task.- Specified by:
parseNLGCompletionResponsein classBasicLLMServiceProvider- Returns:
- The fully populated Utterance to return convertSemanticsToText.
-
getConversationHistoryString
-
getCurrentGoals
-
getCurrentGoalsSummary
-
getCurrentQuestionsString
-
initLearnedActions
protected void initLearnedActions()- Overrides:
initLearnedActionsin classLLMServiceProvider
-
handleDatabaseAddition
public void handleDatabaseAddition(ActionDBEntry entry) throws ai.thinkingrobots.trade.TRADEException - Overrides:
handleDatabaseAdditionin classLLMServiceProvider- Throws:
ai.thinkingrobots.trade.TRADEException
-
handleDatabaseRemoval
public void handleDatabaseRemoval(ActionDBEntry entry) throws ai.thinkingrobots.trade.TRADEException - Overrides:
handleDatabaseRemovalin classLLMServiceProvider- Throws:
ai.thinkingrobots.trade.TRADEException
-
testLLMNLGWithString
-