Move all ModelClient classes into client module.#551
Conversation
* refactor chat streaming * update `_is_token_limit_error` logic * test: add chat provider unittests * move `_is_token_limit_error` to module level * remove unnecessary TYPE_CHECKING * add EOF * update prompt function
* patch: patch adalflow OllamaClient to support batch embedding api. related to SylphAI-Inc/AdalFlow#496 * remove `OllamaDocumentProcessor`
* refactor chat streaming * update `_is_token_limit_error` logic * test: add chat provider unittests * move `_is_token_limit_error` to module level * remove unnecessary TYPE_CHECKING * add EOF * update prompt function * refactor `websocket_wiki.py` using `ChatStreamer` * remove unnecessary imports * add litellm test * update kwargs in `GoogleGenerativeChatStreamer`
# Conflicts: # api/websocket_wiki.py
# Conflicts: # api/chat/_stream.py # api/config.py # api/simple_chat.py
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the project's client integrations by removing local client implementations and unifying all Adalflow-compatible clients under a new centralized api/clients module. This simplifies and standardizes imports across api/chat/_stream.py and api/config.py. The review feedback recommends improving PEP 8 import grouping in api/clients/__init__.py, importing OpenAIClient from the public namespace instead of the internal submodule in api/clients/litellm.py, and sorting the imported clients alphabetically in api/config.py to enhance readability.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| from .google_embedder import GoogleEmbedderClient | ||
| from .bedrock import BedrockClient | ||
| from .dashscope import DashscopeClient | ||
| from .ollama import OllamaClient | ||
| from .litellm import LiteLLMClient | ||
| from .openrouter import OpenRouterClient | ||
| from adalflow.components.model_client import ( | ||
| AzureAIClient, | ||
| OpenAIClient, | ||
| GoogleGenAIClient, | ||
| ) |
There was a problem hiding this comment.
According to PEP 8, imports should be grouped in the following order:
- Standard library imports.
- Related third-party imports.
- Local application/library specific imports.
Currently, the third-party import from adalflow is placed after the local relative imports (e.g., .google_embedder). Placing third-party imports before local relative imports improves readability and adheres to PEP 8 guidelines.
| from .google_embedder import GoogleEmbedderClient | |
| from .bedrock import BedrockClient | |
| from .dashscope import DashscopeClient | |
| from .ollama import OllamaClient | |
| from .litellm import LiteLLMClient | |
| from .openrouter import OpenRouterClient | |
| from adalflow.components.model_client import ( | |
| AzureAIClient, | |
| OpenAIClient, | |
| GoogleGenAIClient, | |
| ) | |
| from adalflow.components.model_client import ( | |
| AzureAIClient, | |
| OpenAIClient, | |
| GoogleGenAIClient, | |
| ) | |
| from .google_embedder import GoogleEmbedderClient | |
| from .bedrock import BedrockClient | |
| from .dashscope import DashscopeClient | |
| from .ollama import OllamaClient | |
| from .litellm import LiteLLMClient | |
| from .openrouter import OpenRouterClient |
| from openai import AsyncOpenAI, OpenAI | ||
|
|
||
| from api.openai_client import OpenAIClient | ||
| from adalflow.components.model_client.openai_client import OpenAIClient |
There was a problem hiding this comment.
Importing OpenAIClient directly from the public namespace adalflow.components.model_client is preferred over importing from the internal submodule adalflow.components.model_client.openai_client. This ensures consistency with other imports in the project and guards against potential internal refactoring of the library.
| from adalflow.components.model_client.openai_client import OpenAIClient | |
| from adalflow.components.model_client import OpenAIClient |
There was a problem hiding this comment.
OpenAIClient in scope model_client is wrapped as an LazyImport instance, which could not be subclassed.
Thus in this scenario, the OpenAIClient must be explicitly imported from openai_client so that LiteLLMClient could inherit from it.
| from api.clients import ( | ||
| LiteLLMClient, | ||
| OpenRouterClient, | ||
| BedrockClient, | ||
| GoogleGenAIClient, | ||
| GoogleEmbedderClient, | ||
| AzureAIClient, | ||
| DashscopeClient, | ||
| OpenAIClient, | ||
| OllamaClient, | ||
| ) |
There was a problem hiding this comment.
Sorting imported names alphabetically within a multi-line import block improves readability and makes it easier to find specific clients as the list grows.
| from api.clients import ( | |
| LiteLLMClient, | |
| OpenRouterClient, | |
| BedrockClient, | |
| GoogleGenAIClient, | |
| GoogleEmbedderClient, | |
| AzureAIClient, | |
| DashscopeClient, | |
| OpenAIClient, | |
| OllamaClient, | |
| ) | |
| from api.clients import ( | |
| AzureAIClient, | |
| BedrockClient, | |
| DashscopeClient, | |
| GoogleEmbedderClient, | |
| GoogleGenAIClient, | |
| LiteLLMClient, | |
| OllamaClient, | |
| OpenAIClient, | |
| OpenRouterClient, | |
| ) |
Summary
under
api/clients/(bedrock,dashscope,litellm,openrouter, ...).openai_clientandazureai_clientmodules.Pros