NeMo-Guardrails icon indicating copy to clipboard operation
NeMo-Guardrails copied to clipboard

On Adding Custom Actions

Open PetreanuAndi opened this issue 2 years ago • 0 comments

Hello Guys,

I'm trying to add a custom action to a custom flow. Lets say i want to extract some fulfilment-table like information from the user interaction. While this table is not complete, i want to loop in the flow.

My flow co looks like this :

define flow invoice
   user asks about invoice details
   $fulfilment_invoice_details = execute check_fulfilment()
   bot responds about invoice details
   while $fulfilment_invoice_details
     bot asks about fulfilment credentials
     user responds to fulfilment credentials
     $fulfilment_invoice_details = execute check_fulfilment()
   bot confirms invoice details
   user says goodbye

my action definition looks like this (draft):

@action()
async def check_fulfilment(context: Optional[dict] = None, llm: Optional[BaseLLM] = None, ):
    bot_response = context.get("last_bot_message")

    chain = create_extraction_chain(llm, fulfilment_table_invoice)
    output = chain.predict_and_parse(text=bot_response)["data"]

    fulfilment_table_result = f"The Fulfilment Table result is : {output}"
    
   # if all details in fulfilment table return True

    return False

I instantiate the rails like this :

config = RailsConfig.from_path(path_to_nemo_bot) rails = LLMRails(config, verbose=True) rails.register_action(check_fulfilment, name="check_fulfilment")

However, no matter what i try, i can not get the system to go into the action code and run the extraction chain. I'm a super rookie with Nemo Guardrails, so any help would be much appreciated. I dont think i missed anything? Is there a better way to extract fulfilment table like information (name / email / account ids etc)?

PetreanuAndi avatar May 09 '23 17:05 PetreanuAndi