NVIDIA / NeMo-Guardrails

NeMo Guardrails is an open-source toolkit for easily adding programmable guardrails to LLM-based conversational systems.
Other
4.22k stars 402 forks source link

Can not find a way to load actions file #738

Closed leizory closed 2 months ago

leizory commented 2 months ago

Is there any way I can specific what action file to be loaded into guardrail ?

DixitAdh commented 2 months ago

@leizory have you looked into custom_data config. You can either pass it in your config.yml or you can assign a value during instantiation of RunnableRails. You can retrieve the value of custom_data from railsconfig instance. I did something like this

config = RailsConfig.from_path(nemo_config_path)
custom_data = dict(blocked_terms_path=blocked_term_path)
config.custom_data = custom_data
guardrails = RunnableRails(config)

Used this custom_data in config.py

  def _get_block_terms(config: RailsConfig):
    df = None
    xlsx_path = config.custom_data.get("blocked_terms_path")
    global blocked_terms_list
    try:
        df = pd.read_excel(xlsx_path)
    except FileNotFoundError:
        print("file {} does not exist".format(xlsx_path))
    blocked_terms_list = [x for x in set(df.to_numpy().flatten().tolist()) if str(x) != 'nan']
Pouyanpi commented 2 months ago

Hi @leizory

Have you consulted this link?

Besides defining actions in actions.py or actions subpackage as explained in the above link. You can use following method of LLMRails

  register_action(action: callable, name: Optional[str] = None):

Have a look at this example.

Please let me know if any of these helps or explain a bit more what you want to achieve.