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

Refactor ApiAssistant to AuthenticatedApiAssistant and UnauthenticatedApiAssistant #381

Conversation

smokestacklightnin
Copy link
Contributor

@smokestacklightnin smokestacklightnin commented Apr 2, 2024

In preparation for adding local assistants that do not require API keys, this PR refactors ragna.assistants._api.ApiAssistant.

This resolves Issue #375.

If anyone has strong opinions about the chosen naming conventions, please share them.

IMPORTANT: This PR should be merged after PR #380 is merged and before PR #376 is merged.

Copy link
Member

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

We misunderstood each other when spoke offline yesterday. What I meant is that we should simply not subclass the OllamaAssistant from the ApiAssistant for now. My original reasoning from #375 holds. I don't want to introduce another abstraction just for a single assistant. We can revisit this later. Until then, I'll close this PR.

self._api_key = os.environ[self._API_KEY_ENV_VAR]


class UnauthenticatedApiAssistant(_ApiAssistant):
Copy link
Member

Choose a reason for hiding this comment

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

This class is not needed. We can simply use the superclass for this.

@classmethod
def requirements(cls) -> list[Requirement]:
return [EnvVarRequirement(cls._API_KEY_ENV_VAR), *cls._extra_requirements()]
return []

@classmethod
def _extra_requirements(cls) -> list[Requirement]:
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if it makes sense to have this on the superclass if for now only the authenticated subclass needs it.

@classmethod
def requirements(cls) -> list[Requirement]:
return [EnvVarRequirement(cls._API_KEY_ENV_VAR), *cls._extra_requirements()]
return []
Copy link
Member

Choose a reason for hiding this comment

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

This is the default return if we don't override the method. Meaning, we can just leave it out here.

Comment on lines +19 to +22
and issubclass(assistant, _ApiAssistant)
and assistant is not _ApiAssistant
and assistant is not AuthenticatedApiAssistant
and assistant is not UnauthenticatedApiAssistant
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
and issubclass(assistant, _ApiAssistant)
and assistant is not _ApiAssistant
and assistant is not AuthenticatedApiAssistant
and assistant is not UnauthenticatedApiAssistant
and issubclass(assistant, AuthenticatedApiAssistant)
and assistant is not AuthenticatedApiAssistant

@pmeier pmeier closed this Apr 2, 2024
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.

ApiAssistant abstract base class for assistants that don't require an API key
2 participants