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

Remove redundant hasattr check in nemoguardrails/llm/params.py #93

Closed

Conversation

serhatgktp
Copy link
Contributor

In Python, the getattr function is used to dynamically retrieve the value of an attribute or to call a method of an object.

Here's the basic syntax of the getattr function:

object: The object from which you want to retrieve the attribute.
attribute_name: A string representing the name of the attribute you want to access.
default: An optional value that will be returned if the attribute does not exist

Since we already have

elif param in getattr(self.llm, "model_kwargs", {}):

If "model_kwargs" is not an attribute of self.llm, the boolean statement will reduce to:

elif param in {}

which will evaluate to false. Therefore, we don't need to check for hasattr(self.llm, "model_kwargs") separately.

Thus, I have removed the hasattr(...) check that precedes the param in getattr(...) check.

Signed-off-by: serhatgktp <efkan@ibm.com>
@drazvan
Copy link
Collaborator

drazvan commented Sep 1, 2023

Thanks for this @serhatgktp ! This got included in this commit caa8ba3. There is still an unresolved issue though, hence the commenting. Closing this.

@drazvan drazvan closed this Sep 1, 2023
@drazvan drazvan self-assigned this Sep 1, 2023
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