Skip to content

Commit 3b6845f

Browse files
author
jinhaiyang
committed
Merge branch 'main' into feature/web-search-0410
s the commit.
2 parents ea34fc1 + 9a730e7 commit 3b6845f

File tree

6 files changed

+70
-25
lines changed

6 files changed

+70
-25
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "zhipuai"
3-
version = "2.1.5.20250106"
3+
version = "2.1.5.20250410"
44
description = "A SDK library for accessing big model apis from ZhipuAI"
55
authors = ["Zhipu AI"]
66
readme = "README.md"

tests/integration_tests/test_assistant.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import os
21
import logging
32
import logging.config
43
import zhipuai
54
from zhipuai import ZhipuAI
6-
5+
import json
76

87
def test_assistant(logging_conf) -> None:
98
logging.config.dictConfig(logging_conf) # type: ignore
@@ -12,7 +11,6 @@ def test_assistant(logging_conf) -> None:
1211

1312
generate = client.assistant.conversation(
1413
assistant_id="659e54b1b8006379b4b2abd6",
15-
model="glm-4-assistant",
1614
messages=[
1715
{
1816
"role": "user",
@@ -73,3 +71,41 @@ def test_assistant_query_conversation_usage(logging_conf) -> None:
7371
print(err)
7472
except zhipuai.core._errors.APIStatusError as err:
7573
print(err)
74+
75+
76+
def test_translate_api(logging_conf) -> None:
77+
logging.config.dictConfig(logging_conf) # type: ignore
78+
client = ZhipuAI() # 填写您自己的APIKey
79+
try:
80+
translate_response = client.assistant.conversation(
81+
assistant_id="9996ijk789lmn012o345p999",
82+
messages=[
83+
{
84+
"role": "user",
85+
"content": [{
86+
"type": "text",
87+
"text": "你好呀"
88+
}]
89+
}
90+
],
91+
stream=True,
92+
attachments=None,
93+
metadata=None,
94+
request_id="request_1790291013237211136",
95+
user_id="12345678",
96+
extra_parameters = {
97+
"translate": {
98+
"from": "zh",
99+
"to": "en"
100+
}
101+
}
102+
)
103+
for chunk in translate_response:
104+
print(chunk.choices[0].delta)
105+
#print(translate_response)
106+
except zhipuai.core._errors.APIRequestFailedError as err:
107+
print(err)
108+
except zhipuai.core._errors.APIInternalError as err:
109+
print(err)
110+
except zhipuai.core._errors.APIStatusError as err:
111+
print(err)

tests/integration_tests/test_charglm3.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ def test_async_completions():
6868
except zhipuai.core._errors.APIStatusError as err:
6969
print(err)
7070

71-
def test_retrieve_completion_result():
72-
client = ZhipuAI() # 请填写您自己的APIKey
73-
try:
74-
response = client.chat.asyncCompletions.retrieve_completion_result(id="1014908592669352541650991")
75-
print(response)
76-
77-
78-
except zhipuai.core._errors.APIRequestFailedError as err:
79-
print(err)
80-
except zhipuai.core._errors.APIInternalError as err:
81-
print(err)
82-
83-
if __name__ == "__main__":
84-
test_retrieve_completion_result()
71+
# def test_retrieve_completion_result():
72+
# client = ZhipuAI() # 请填写您自己的APIKey
73+
# try:
74+
# response = client.chat.asyncCompletions.retrieve_completion_result(id="1014908592669352541650991")
75+
# print(response)
76+
#
77+
#
78+
# except zhipuai.core._errors.APIRequestFailedError as err:
79+
# print(err)
80+
# except zhipuai.core._errors.APIInternalError as err:
81+
# print(err)
82+
83+
# if __name__ == "__main__":
84+
# test_retrieve_completion_result()

tests/integration_tests/test_code_geex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_code_geex(logging_conf):
2222
{
2323
"role": "system",
2424
"content": """你是一位智能编程助手,你叫CodeGeeX。你会为用户回答关于编程、代码、计算机方面的任何问题,并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。
25-
任务:请为输入代码提供格式规范的注释,包含多行注释和单行注释,请注意不要改动原始代码,只需要添加注释。
25+
任务:请为输入代码提供格式规范的注释,包含多行注释和单行注释,请注意不要改动原始代码,只需要添加注释。
2626
请用中文回答。"""
2727
},
2828
{
@@ -74,7 +74,7 @@ def test_code_geex_async(logging_conf):
7474
{
7575
"role": "system",
7676
"content": """你是一位智能编程助手,你叫CodeGeeX。你会为用户回答关于编程、代码、计算机方面的任何问题,并提供格式规范、可以执行、准确安全的代码,并在必要时提供详细的解释。
77-
任务:请为输入代码提供格式规范的注释,包含多行注释和单行注释,请注意不要改动原始代码,只需要添加注释。
77+
任务:请为输入代码提供格式规范的注释,包含多行注释和单行注释,请注意不要改动原始代码,只需要添加注释。
7878
请用中文回答。"""
7979
},
8080
{

zhipuai/api_resource/assistant/assistant.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,31 @@ def __init__(self, client: "ZhipuAI") -> None:
3333
def conversation(
3434
self,
3535
assistant_id: str,
36-
model: str,
3736
messages: List[assistant_create_params.ConversationMessage],
37+
model: str = None,
3838
*,
39-
stream: bool = True,
39+
stream: Optional[Literal[False]] | Literal[True] | NotGiven = NOT_GIVEN,
4040
conversation_id: Optional[str] = None,
4141
attachments: Optional[List[assistant_create_params.AssistantAttachments]] = None,
4242
metadata: dict | None = None,
4343
request_id: str = None,
4444
user_id: str = None,
45+
extra_parameters: Optional[assistant_create_params.ExtraParameters] = None,
4546
extra_headers: Headers | None = None,
4647
extra_body: Body | None = None,
4748
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
48-
) -> StreamResponse[AssistantCompletion]:
49+
) -> AssistantCompletion | StreamResponse[AssistantCompletion]:
4950
body = deepcopy_minimal(
5051
{
5152
"assistant_id": assistant_id,
52-
"model": model,
5353
"messages": messages,
5454
"stream": stream,
5555
"conversation_id": conversation_id,
5656
"attachments": attachments,
5757
"metadata": metadata,
5858
"request_id": request_id,
5959
"user_id": user_id,
60+
"extra_parameters": extra_parameters
6061
}
6162
)
6263
return self._post(
@@ -66,7 +67,7 @@ def conversation(
6667
extra_headers=extra_headers, extra_body=extra_body, timeout=timeout
6768
),
6869
cast_type=AssistantCompletion,
69-
stream=stream or True,
70+
stream=stream or False,
7071
stream_cls=StreamResponse[AssistantCompletion],
7172
)
7273

zhipuai/types/assistant/assistant_create_params.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ class AssistantParameters(TypedDict, total=False):
2828
messages: List[ConversationMessage] # 会话消息体
2929
attachments: Optional[List[AssistantAttachments]] # 会话指定的文件,非必填
3030
metadata: Optional[dict] # 元信息,拓展字段,非必填
31+
32+
class TranslateParameters(TypedDict, total=False):
33+
from_language: str
34+
to_language: str
35+
36+
class ExtraParameters(TypedDict, total=False):
37+
translate: TranslateParameters
38+

0 commit comments

Comments
 (0)