Skip to content

Improve provider selection logic in Config.get_provider_for method#297

Open
lenage wants to merge 2 commits into
MadcowD:mainfrom
byteb:main
Open

Improve provider selection logic in Config.get_provider_for method#297
lenage wants to merge 2 commits into
MadcowD:mainfrom
byteb:main

Conversation

@lenage

@lenage lenage commented Oct 9, 2024

Copy link
Copy Markdown

Description

This PR enhances the get_provider_for method in the Config class to provide more accurate and efficient provider selection. The updated implementation prioritizes exact matches and then selects the most specific subclass when dealing with inheritance hierarchies.

Changes

  • Modified get_provider_for method to first check for an exact match between the client type and available providers.
  • If no exact match is found, the method now identifies all matching providers based on subclass relationships.
  • Implemented a sorting mechanism to select the most specific (derived) provider when multiple matches are found.

Testing

create a new ProviderClass which is a subclass of OpenAIProvider

class AwesomeProvider(OpenAIProvider):
    def translate_to_provider(self, ell_call: EllCallParams) -> Dict[str, Any]:
         #make some changes

    def translate_from_provider(self,
                                provider_response,
                                ell_call: EllCallParams,
                                provider_call_params: Dict[str, Any],
                                origin_id: str | None = None,
                                logger: Callable[..., None] | None = None) -> Tuple[List[Message] | Dict[str, Any]]:
        return super().translate_from_provider(provider_response, ell_call, provider_call_params, origin_id, logger)

ell.register_provider(AwesomeProvider())

then, if you call ell.simple, it always use OpenAIProvider instead of AwesomeProvider
This PR fix above issue to check inheritance hierarchies

Additional Notes

This change maintains backwards compatibility while providing more precise provider selection, especially in cases involving complex inheritance hierarchies.

@MadcowD

MadcowD commented Oct 11, 2024

Copy link
Copy Markdown
Owner

I'll take a quick look

@MadcowD

MadcowD commented Oct 12, 2024

Copy link
Copy Markdown
Owner

Would you be willing to add a few tests for this PR?

@MadcowD

MadcowD commented Oct 12, 2024

Copy link
Copy Markdown
Owner

Ready to merge just dont want to have regressions in the future

@lenage

lenage commented Oct 13, 2024

Copy link
Copy Markdown
Author

Would you be willing to add a few tests for this PR?

sure, will add some test soon

@lenage

lenage commented Oct 13, 2024

Copy link
Copy Markdown
Author

Would you be willing to add a few tests for this PR?

sure, will add some test soon

@MadcowD tests added

@lenage

lenage commented Oct 21, 2024

Copy link
Copy Markdown
Author

@MadcowD have a sec to check this out?

@MadcowD

MadcowD commented Oct 21, 2024

Copy link
Copy Markdown
Owner

Can you add an assertion error or a Warnung if there are two mstching providers of the same mro lehnte

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