-
Notifications
You must be signed in to change notification settings - Fork 376
reface the interface of online models #1074
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
|
|
||
| from ...servermodule import LLMBase, StaticParams | ||
| from .base import OnlineChatModuleBase | ||
| from .base.utils import select_source_with_default_key | ||
| from .base.utils import select_source_with_default_key, resolve_online_params | ||
| from .dynamic_router import _DynamicSourceRouterMixin, dynamic_model_config_context | ||
|
|
||
|
|
||
|
|
@@ -32,35 +32,38 @@ class OnlineChatModule(_DynamicSourceRouterMixin, LLMBase, metaclass=_ChatModule | |
| _dynamic_module_slot = 'chat' | ||
| _dynamic_source_error = 'No source is configured for dynamic LLM source.' | ||
|
|
||
| def __new__(cls, model: str = None, source: str = None, base_url: str = None, stream: bool = True, | ||
| def __new__(cls, model: str = None, source: str = None, url: str = None, stream: bool = True, | ||
| return_trace: bool = False, skip_auth: bool = False, type: Optional[str] = None, | ||
| api_key: str = None, static_params: Optional[StaticParams] = None, id: Optional[str] = None, | ||
| name: Optional[str] = None, group_id: Optional[str] = None, dynamic_auth: bool = False, **kwargs): | ||
| if model in lazyllm.online.chat and source is None: source, model = model, source | ||
| model, source, url, kwargs = resolve_online_params( | ||
| model, source, url, kwargs, url_aliases='base_url', source_registry=lazyllm.online.chat) | ||
|
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with AutoModel and other online modules, OnlineChatModule should also resolve model_name and base_model aliases into the model parameter. Currently, these remain in kwargs, which might lead to unexpected behavior or duplicate parameters being passed to the underlying supplier. model, source, url, kwargs = resolve_online_params(
model, source, url, kwargs, model_aliases=('model_name', 'base_model'),
url_aliases='base_url', source_registry=lazyllm.online.chat) |
||
| if cls._should_use_dynamic(source, dynamic_auth, skip_auth): | ||
| return super().__new__(cls) | ||
|
|
||
| if source is None and api_key is not None: | ||
| raise ValueError('No source is given but an api_key is provided.') | ||
| source, default_key = select_source_with_default_key(lazyllm.online.chat, source, LLMType.CHAT) | ||
| api_key = api_key if api_key is not None else default_key | ||
| if skip_auth and not base_url: | ||
| raise KeyError('base_url must be set for local serving.') | ||
| if skip_auth and not url: | ||
| raise ValueError('url must be set for local serving.') | ||
|
|
||
| type = cls._resolve_type_name(type, model, options=[LLMType.LLM, LLMType.CHAT, LLMType.VLM]) | ||
| return getattr(lazyllm.online.chat, source)( | ||
| base_url=base_url, model=model, stream=stream, return_trace=return_trace, | ||
| base_url=url, model=model, stream=stream, return_trace=return_trace, | ||
| api_key=api_key, skip_auth=skip_auth, type=type, **kwargs) | ||
|
|
||
| def __init__(self, model: str = None, source: str = None, base_url: str = None, stream: bool = True, | ||
| def __init__(self, model: str = None, source: str = None, url: str = None, stream: bool = True, | ||
| return_trace: bool = False, skip_auth: bool = False, type: Optional[str] = None, | ||
| api_key: str = None, static_params: Optional[StaticParams] = None, id: Optional[str] = None, | ||
| name: Optional[str] = None, group_id: Optional[str] = None, dynamic_auth: bool = False, **kwargs): | ||
| model, source, url, kwargs = resolve_online_params( | ||
| model, source, url, kwargs, url_aliases='base_url', source_registry=lazyllm.online.chat) | ||
| normalized_type = self._resolve_type_name(type, model, options=[LLMType.LLM, LLMType.CHAT, LLMType.VLM]) | ||
| _DynamicSourceRouterMixin.__init__(self, id=id, name=name, group_id=group_id, return_trace=return_trace) | ||
| LLMBase.__init__(self, stream=stream, type=normalized_type, static_params=static_params) | ||
| self._kwargs = kwargs | ||
| self._base_url = base_url | ||
| self._base_url = url | ||
| self._model_name = model | ||
| self._skip_auth = skip_auth | ||
| self._init_dynamic_auth(api_key, dynamic_auth) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for swapping model and source is incorrect when source is already provided but not present in the source_registry (e.g., when using source='dynamic'). Currently, if model is a recognized source name and source is set to something else (like 'dynamic'), the function will swap them because _in(source) will be false. This breaks dynamic routing by setting source to the model name and model to 'dynamic'. The swap should only occur if source is None. If both are provided and model is a recognized source, it should raise a ValueError to avoid ambiguity, consistent with the check added in automodel.py.