NVIDIA / NeMo-Guardrails

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

Actions not being imported correctly #615

Closed d-shree closed 2 weeks ago

d-shree commented 2 weeks ago

I have created a FastAPI based application that uses NeMo-Guardrails for handling the conversation flow. This works fine locally however when I run the application as a docker container. I see the following error -

Bot message: "Action 'extract_masked_text' not found."[/]

where extract_masked_text is a custom action I have defined in actions.py file.

I have also noticed that the prompts used to generate_user_intent have very different examples picked up for Input which is a zip code

The examples picked up in the prompt used in local machine -

`This is how the user talks:[/]
[cyan]User[/][black on white]
<ZIP>[/]
[cyan]Bot[/][black on white]
User intent: provide zip code[/]
[cyan]User[/][black on white]
it is <ZIP>[/]
[cyan]Bot[/][black on white]
User intent: provide zip code[/]
[cyan]User[/][black on white]
Actual, Zip code is <ZIP>[/]
[cyan]Bot[/][black on white]
User intent: provide zip code[/]
[cyan]User[/][black on white]
<ZIP> is the zip code[/]
[cyan]Bot[/][black on white]
User intent: provide zip code[/]
[cyan]User[/][black on white]
My zip code is <ZIP>[/]
[cyan]Bot[/][black on white]
User intent: provide zip code[/]
[cyan]System[/][black on white]
This is the current conversation between the user and the bot:[/]
[cyan]Bot[/][black on white]`

The examples picked up in the docker container -

`[cyan]System[/][black on white]
This is how the user talks:[/]
[cyan]User[/][black on white]
You are calling the wrong person[/]
[cyan]Bot[/][black on white]
User intent: informs wrong number[/]
[cyan]User[/][black on white]
I am not the person you are looking for[/]
[cyan]Bot[/][black on white]
User intent: informs wrong number[/]
[cyan]User[/][black on white]
Yes that's me[/]
[cyan]Bot[/][black on white]
User intent: confirms identity[/]
[cyan]User[/][black on white]
<PERSON> passed away[/]
[cyan]Bot[/][black on white]
User intent: replies deceased[/]
[cyan]User[/][black on white]
Yes you are talking to <PERSON>[/]
[cyan]Bot[/][black on white]
User intent: confirms identity[/]
[cyan]System[/][black on white]`

Can somebody help me figure out what is going wrong here?

drazvan commented 2 weeks ago

@d-shree : can you provide more details?

d-shree commented 2 weeks ago

@drazvan

  1. The guardrails are initialised as follows -
client = ChatOpenAI(
      api_key=OPEN_AI_KEY,
  )
config = RailsConfig.from_content(
    colang_content=colang_flow,
    yaml_content=config_content
)

rails = LLMRails(config=config, llm=client)
  1. Nope, not using built-in server
  2. The Dockerfile is pretty straightforward as shown below, the colang flows are being passed via the request payload and actions are configured in a file called actions.py, using the@action decorator.
    
    FROM python:3.9

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8009

CMD ["uvicorn", "src.endpoints:app", "--host", "0.0.0.0", "--port", "8076"]`

drazvan commented 2 weeks ago

@d-shree: actions are loaded automatically from the actions.py file when the configuration is loaded from a path. If you're creating the RailsConfig instance with from_content, you need to manually register the actions using rails.register_action. Let me know if this solves the issue with the action not found.

d-shree commented 2 weeks ago

This worked, but its strange that this error did not show up while testing normally, which was why I was having a hard time figuring out the exact cause of this issue.