Skip to content

Commit

Permalink
feat: models() 支持作为 class method (#606)
Browse files Browse the repository at this point in the history
* models() support as classmethod

* fix lint

* fix lint
  • Loading branch information
ZingLix committed Jun 28, 2024
1 parent ec0e4fe commit e811ee2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion python/qianfan/resources/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,20 @@ def access_token(self) -> str:
"""
return self._real.access_token()

def models(self) -> Set[str]:
@utils.class_or_instancemethod
def models(
self_or_cls,
/,
version: Optional[Literal["1", "2", 1, 2]] = None,
*args: Any,
**kwargs: Any,
) -> Set[str]:
if version is not None:
return self_or_cls._real_base(str(version)).models()
if isinstance(self_or_cls, type):
cls = self_or_cls
return cls._real_base(version="1").models()
self = self_or_cls
return self._real.models()

def get_model_info(self, model: str) -> QfLLMInfo:
Expand Down
6 changes: 6 additions & 0 deletions python/qianfan/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,9 @@ def get_ip_address() -> str:
return "127.0.0.1"

return s.getsockname()[0] # type: ignore


class class_or_instancemethod(classmethod):
def __get__(self, instance: _T, type_: Optional[Type[_T]] = None, /) -> Callable:
descr_get = super().__get__ if instance is None else self.__func__.__get__
return descr_get(instance, type_)

0 comments on commit e811ee2

Please sign in to comment.