feat: switchtozhipu (#12)
Co-authored-by: zhengweijun <weijun.zheng@aminer.cn>
This commit is contained in:
parent
42a921e770
commit
ee0a2b3e4c
2 changed files with 16 additions and 5 deletions
|
|
@ -158,11 +158,21 @@ def audio_transcription():
|
|||
)
|
||||
print(response.text)
|
||||
|
||||
def ofZhipu():
|
||||
client = ZaiClient()
|
||||
response = client.zhipu.chat.completions.create(
|
||||
model='glm-4',
|
||||
messages=[{'role': 'user', 'content': 'Hello, Z.ai!'}],
|
||||
temperature=0.7,
|
||||
)
|
||||
print(response.choices[0].message.content)
|
||||
|
||||
if __name__ == '__main__':
|
||||
completion()
|
||||
# completion()
|
||||
# completion_with_websearch()
|
||||
# multi_modal_chat()
|
||||
# role_play()
|
||||
# assistant_conversation()
|
||||
# video_generation()
|
||||
ofZhipu()
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ class ZaiClient(HttpClient):
|
|||
disable_token_cache: bool = True,
|
||||
_strict_response_validation: bool = False,
|
||||
source_channel: str | None = None,
|
||||
switch_to_zhipu: bool = False,
|
||||
) -> None:
|
||||
"""
|
||||
Initialize the ZAI client
|
||||
|
|
@ -79,7 +78,6 @@ class ZaiClient(HttpClient):
|
|||
disable_token_cache (bool): Whether to disable JWT token caching
|
||||
_strict_response_validation (bool): Whether to enable strict response validation
|
||||
source_channel (str | None): Source channel identifier
|
||||
switch_to_zhipu (bool): Whether to switch to Zhipu base_url
|
||||
"""
|
||||
if api_key is None:
|
||||
api_key = os.environ.get('ZAI_API_KEY')
|
||||
|
|
@ -93,8 +91,6 @@ class ZaiClient(HttpClient):
|
|||
base_url = os.environ.get('ZAI_BASE_URL')
|
||||
if base_url is None:
|
||||
base_url = 'https://api.z.ai/api/paas/v4'
|
||||
if switch_to_zhipu:
|
||||
base_url = 'https://open.bigmodel.cn/api/paas/v4'
|
||||
from ._version import __version__
|
||||
|
||||
super().__init__(
|
||||
|
|
@ -107,6 +103,11 @@ class ZaiClient(HttpClient):
|
|||
_strict_response_validation=_strict_response_validation,
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def zhipu(self):
|
||||
self.base_url = 'https://open.bigmodel.cn/api/paas/v4'
|
||||
return self
|
||||
|
||||
@cached_property
|
||||
def chat(self) -> Chat:
|
||||
from zai.api_resource.chat import Chat
|
||||
|
|
|
|||
Loading…
Reference in a new issue