Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/issue 335 visible import errors #550

Merged
merged 9 commits into from
Jun 11, 2024

Conversation

Pouyanpi
Copy link
Collaborator

@Pouyanpi Pouyanpi commented Jun 7, 2024

Summary

This PR refines the action_dispatcher.py module by enhancing the visibility of errors during action imports and discovery. It resoves #335 .

@Pouyanpi Pouyanpi requested a review from drazvan June 7, 2024 06:28
Copy link
Collaborator

@drazvan drazvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When starting the ABC bot now, there are a bunch of errors which show up:

$ nemoguardrails chat --config=examples/bots/abc
Failed to register __init__.py in action dispatcher due to exception No module named '__init__'
Failed to register __init__.py in action dispatcher due to exception No module named '__init__'
Failed to register base.py in action dispatcher due to exception No module named 'base'
Failed to register actions.py in action dispatcher due to exception No module named 'spacy'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register __init__.py in action dispatcher due to exception No module named '__init__'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register __init__.py in action dispatcher due to exception No module named '__init__'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register base.py in action dispatcher due to exception No module named 'base'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register actions.py in action dispatcher due to exception No module named 'spacy'
Fetching 7 files: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<00:00, 110792.94it/s]
Starting the chat (Press Ctrl + C twice to quit) ...
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register __init__.py in action dispatcher due to exception No module named '__init__'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register __init__.py in action dispatcher due to exception No module named '__init__'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register base.py in action dispatcher due to exception No module named 'base'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register actions.py in action dispatcher due to exception No module named 'spacy'

>

I think this is related to some of the default actions we're registering from nemoguardrails.actions.langchain. We should disable the default loading for them, as they're not used and enable them with a flag --load-demo-actions for the CLI (which should translate to a load_demo_actions for the LLMRails). Default False.

@drazvan drazvan self-assigned this Jun 7, 2024
@drazvan drazvan added this to the v0.10.0 milestone Jun 7, 2024
@Pouyanpi
Copy link
Collaborator Author

Pouyanpi commented Jun 7, 2024

@drazvan, after enriching the log

Failed to register __init__.py from nemoguardrails/actions/init.py in action dispatcher due to exception: No module named 'init'
Failed to register init.py from nemoguardrails/actions/validation/init.py in action dispatcher due to exception: No module named 'init'
Failed to register base.py from nemoguardrails/actions/validation/base.py in action dispatcher due to exception: No module named 'base'
Failed to register actions.py from nemoguardrails/library/hallucination/actions.py in action dispatcher due to exception: No module named 'langchain_openai'
Failed to register actions.py from nemoguardrails/library/sensitive_data_detection/actions.py in action dispatcher due to exception: No module named 'spacy'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register init.py from nemoguardrails/actions/init.py in action dispatcher due to exception: No module named 'init'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register init.py from nemoguardrails/actions/validation/init.py in action dispatcher due to exception: No module named 'init'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register base.py from nemoguardrails/actions/validation/base.py in action dispatcher due to exception: No module named 'base'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register actions.py from nemoguardrails/library/hallucination/actions.py in action dispatcher due to exception: No module named 'langchain_openai'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register actions.py from nemoguardrails/library/sensitive_data_detection/actions.py in action dispatcher due to exception: No module named 'spacy'
NeMo-Guardrails/env/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The class OpenAI was deprecated in LangChain 0.0.10 and will be removed in 0.3.0. An updated version of the class exists in the langchain-openai package and should be used instead. To use it run pip install -U langchain-openai and import as from langchain_openai import OpenAI.
warn_deprecated(
Fetching 5 files: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 35305.59it/s]
Starting the chat (Press Ctrl + C twice to quit) ...
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register init.py from nemoguardrails/actions/init.py in action dispatcher due to exception: No module named 'init'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register init.py from nemoguardrails/actions/validation/init.py in action dispatcher due to exception: No module named 'init'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register base.py from nemoguardrails/actions/validation/base.py in action dispatcher due to exception: No module named 'base'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register actions.py from nemoguardrails/library/hallucination/actions.py in action dispatcher due to exception: No module named 'langchain_openai'
ERROR:nemoguardrails.actions.action_dispatcher:Failed to register actions.py from nemoguardrails/library/sensitive_data_detection/actions.py in action dispatcher due to exception: No module named 'spacy'

so this is related to all files under actions that are optional dependency, spacy and langchain_openai. But for init.py we must skip it and base.py should be imported relative to the project structure.

To fix this, maybe, I can modify the load_actions_from_path method to ignore init.py files and to import other files relative to the package structure. Also I can import other packages lazily.

What do you think?

Lastly, please not that deprecation warning.

@Pouyanpi
Copy link
Collaborator Author

Pouyanpi commented Jun 7, 2024

@drazvan, I added a temporary fix.

@drazvan drazvan self-requested a review June 11, 2024 12:17
Copy link
Collaborator

@drazvan drazvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pouyanpi : I've made a few additional changes. I think it's good to merge, have a look.

@Pouyanpi
Copy link
Collaborator Author

@drazvan, Nice! It looks good to me.

@drazvan drazvan merged commit e03244c into develop Jun 11, 2024
4 checks passed
@Pouyanpi Pouyanpi deleted the feat/issue-335-visible-import-errors branch July 4, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants