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

chore: update return type to Optional[str] #982

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

leseb
Copy link
Contributor

@leseb leseb commented Feb 6, 2025

What does this PR do?

Updated the return type of the methods get_provider_model_id and get_llama_model in the ModelRegistryHelper class to Optional[str] to indicate that they may return a string or None when no match is found. This change improves the clarity of the methods' behavior and supports better type safety.

Signed-off-by: Sébastien Han seb@redhat.com

  • Addresses issue (#issue)

Test Plan

Please describe:

  • tests you ran to verify your changes with result summaries.
  • provide instructions so it can be reproduced.

Sources

Please link relevant resources if necessary.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Ran pre-commit to handle lint / formatting issues.
  • Read the contributor guideline,
    Pull Request section?
  • Updated relevant documentation.
  • Wrote necessary unit or integration tests.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 6, 2025
Copy link
Collaborator

@terrytangyuan terrytangyuan left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -57,13 +57,13 @@ def __init__(self, model_aliases: List[ModelAlias]):
self.alias_to_provider_id_map[alias_obj.llama_model] = alias_obj.provider_model_id
self.provider_id_to_llama_model_map[alias_obj.provider_model_id] = alias_obj.llama_model

def get_provider_model_id(self, identifier: str) -> str:
def get_provider_model_id(self, identifier: str) -> Optional[str]:
if identifier in self.alias_to_provider_id_map:
Copy link
Contributor

Choose a reason for hiding this comment

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

whole thing could be just self.alias_to_provider_id_map.get(identifier, None) I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! @ashwinb PTAL

Updated the return type of the methods `get_provider_model_id` and
`get_llama_model` in the `ModelRegistryHelper` class to `Optional[str]`
to indicate that they may return a string or None when no match is
found. This change improves the clarity of the methods' behavior and
supports better type safety.
Replaced explicit `if-else` checks with `dict.get()` for cleaner code.

Signed-off-by: Sébastien Han <seb@redhat.com>
@yanxi0830 yanxi0830 merged commit bf11cc0 into meta-llama:main Feb 12, 2025
3 checks passed
@leseb leseb deleted the add-optional-str branch February 12, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants