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

AttributeError: 'FastAPI' object has no attribute 'register_action'

Open mojo2405 opened this issue 2 years ago • 3 comments

Hi,

I want to use the 'nemoguardrails server' in the same way I use 'nemoguardrails chat' But, when I set an 'init' function inside my config.py, the passed parameter to the 'init' function is not LLMRails but the FastAPI object. That means, that I cannot use, for example, the function register_action (which actually works fine when running ('nemoguardrails chat')

An example of the init function:

def init(app: LLMRails):
    
    app.register_action(action=retrieve, name="retrieve")
    app.register_action(action=rag, name="rag")

It looks like a bug or needs some clarification. Thanks!

mojo2405 avatar Feb 12 '24 12:02 mojo2405

Hi @mojo2405!

I think I know what the issue is in your case. The server is meant to work with multiple configs, so it needs to be pointed to a folder with subfolders for each config. https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/docs/user_guides/server-guide.md#guardrails-server

I assume you've started the server, but pointed it to the folder for a single config. The server can also use a config.py which is must be located at the root of the configs. So, in this case, it is mistakenly taking the config.py meant for the configuration as the config.py for the server. And hence why it passes a FastAPI object.

The quick workaround now is to just create another subfloder for the config. I'll create an issue to allow the server to work with a single config. We've seen this type of confusion a few times.

.
├── config
│   ├── config_1
│   │   ├── file_1.co
│   │   └── config.yml
│   ├── config_2
│       ├── ...
│   ...
│   ├── config.py

drazvan avatar Feb 12 '24 14:02 drazvan

Hi @mojo2405!

I think I know what the issue is in your case. The server is meant to work with multiple configs, so it needs to be pointed to a folder with subfolders for each config. https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/docs/user_guides/server-guide.md#guardrails-server

I assume you've started the server, but pointed it to the folder for a single config. The server can also use a config.py which is must be located at the root of the configs. So, in this case, it is mistakenly taking the config.py meant for the configuration as the config.py for the server. And hence why it passes a FastAPI object.

The quick workaround now is to just create another subfloder for the config. I'll create an issue to allow the server to work with a single config. We've seen this type of confusion a few times.

.
├── config
│   ├── config_1
│   │   ├── file_1.co
│   │   └── config.yml
│   ├── config_2
│       ├── ...
│   ...
│   ├── config.py

@drazvan I am facing the same issue running the hf llama 2 example in nemoguardrails. I tried copying the hf_pipeline_llama2 directory twice under a new folder named master_config with different names like config_1 and config_2. I tried moving moving the config.py to the new master_config_folder but it didnt work. Either the server started too quickly without loading any model or I get the FastApi error.

Would appreciate if you could provide some details. I am a nemoguardrails newbie

Thanks in advance

Ajay

nairajay2k avatar Feb 26 '24 14:02 nairajay2k

See https://github.com/NVIDIA/NeMo-Guardrails/issues/361.

drazvan avatar Feb 27 '24 12:02 drazvan