-
Notifications
You must be signed in to change notification settings - Fork 123
LLM Client Factory #150
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
Merged
Merged
LLM Client Factory #150
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1d8c5b6
Refactor LLMClient to use LemonadeClient instead of raw OpenAI SDK
itomek 582d207
Update imports to use new LLM client architecture
itomek f047a9c
Fix issues from Copilot PR review
itomek 6d3b26f
Address PR #150 review comments
itomek 30fcc6e
Fix test failures from LLM client refactoring
itomek cc16d8b
Refactor code structure for improved readability and maintainability
itomek d7a2c89
Merge branch 'main' into llm-refactor
itomek a297c0a
Merge branch 'main' into llm-refactor
kovtcharov-amd 10dc01a
Merge branch 'main' into llm-refactor
kovtcharov-amd d643cf5
Merge branch 'main' into llm-refactor
kovtcharov-amd 2e25dad
Merge branch 'main' into llm-refactor
kovtcharov-amd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| packages=[ | ||
| "gaia", | ||
| "gaia.llm", | ||
| "gaia.llm.providers", | ||
| "gaia.audio", | ||
| "gaia.chat", | ||
| "gaia.database", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,9 @@ | ||
| # Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
| """LLM client package.""" | ||
|
|
||
| from .base_client import LLMClient | ||
| from .exceptions import NotSupportedError | ||
| from .factory import create_client | ||
|
|
||
| __all__ = ["create_client", "LLMClient", "NotSupportedError"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
| """Base LLM client interface.""" | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import Iterator, Union | ||
|
|
||
| from .exceptions import NotSupportedError | ||
|
|
||
|
|
||
| class LLMClient(ABC): | ||
| """ | ||
| Unified LLM client interface. | ||
|
|
||
| Methods raise NotSupportedError if not available for this provider. | ||
| """ | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def provider_name(self) -> str: | ||
| """Return the provider name for error messages.""" | ||
| ... | ||
|
|
||
| @abstractmethod | ||
| def generate( | ||
| self, | ||
| prompt: str, | ||
| model: str | None = None, | ||
| stream: bool = False, | ||
| **kwargs, | ||
| ) -> Union[str, Iterator[str]]: | ||
| """Generate text completion.""" | ||
| ... | ||
|
|
||
| @abstractmethod | ||
| def chat( | ||
| self, | ||
| messages: list[dict], | ||
| model: str | None = None, | ||
| stream: bool = False, | ||
| **kwargs, | ||
| ) -> Union[str, Iterator[str]]: | ||
| """Chat completion.""" | ||
| ... | ||
|
|
||
| # Optional - default raises NotSupportedError | ||
| def embed(self, texts: list[str], **kwargs) -> list[list[float]]: | ||
| raise NotSupportedError(self.provider_name, "embed") | ||
|
|
||
| def vision(self, images: list[bytes], prompt: str, **kwargs) -> str: | ||
| raise NotSupportedError(self.provider_name, "vision") | ||
|
|
||
| def get_performance_stats(self) -> dict: | ||
| raise NotSupportedError(self.provider_name, "get_performance_stats") | ||
|
|
||
| def load_model(self, model_name: str, **kwargs) -> None: | ||
| raise NotSupportedError(self.provider_name, "load_model") | ||
|
|
||
| def unload_model(self) -> None: | ||
| raise NotSupportedError(self.provider_name, "unload_model") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright(C) 2025-2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
| """LLM client exceptions.""" | ||
|
|
||
|
|
||
| class NotSupportedError(Exception): | ||
| """Raised when a provider doesn't support a method.""" | ||
|
|
||
| def __init__(self, provider: str, method: str): | ||
| self.provider = provider | ||
| self.method = method | ||
| super().__init__(f"{provider} does not support {method}") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.