Skip to content

Commit da5961e

Browse files
author
jinhaiyang
committed
Merge branch 'main' into feature/source_channel
2 parents 7a510a1 + a416cab commit da5961e

File tree

12 files changed

+122
-16
lines changed

12 files changed

+122
-16
lines changed

.github/workflows/_release.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,19 @@ jobs:
154154
--extra-index-url https://test.pypi.org/simple/ \
155155
"$PKG_NAME==$VERSION"
156156
157-
- name: Run unit tests
158-
run: make tests
159-
env:
160-
ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
161-
ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
162-
working-directory: ${{ inputs.working-directory }}
157+
# - name: Run unit tests
158+
# run: make tests
159+
# env:
160+
# ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
161+
# ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
162+
# working-directory: ${{ inputs.working-directory }}
163163

164-
- name: Run integration tests
165-
env:
166-
ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
167-
ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
168-
run: make integration_tests
169-
working-directory: ${{ inputs.working-directory }}
164+
# - name: Run integration tests
165+
# env:
166+
# ZHIPUAI_API_KEY: ${{ secrets.ZHIPUAI_API_KEY }}
167+
# ZHIPUAI_BASE_URL: ${{ secrets.ZHIPUAI_BASE_URL }}
168+
# run: make integration_tests
169+
# working-directory: ${{ inputs.working-directory }}
170170

171171
publish:
172172
needs:

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.20250526"
3+
version = "2.1.5.20250611"
44
description = "A SDK library for accessing big model apis from ZhipuAI"
55
authors = ["Zhipu AI"]
66
readme = "README.md"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os.path
2+
3+
from zhipuai import ZhipuAI
4+
import zhipuai
5+
import time
6+
7+
import logging
8+
import logging.config
9+
10+
11+
def test_completions_temp0(logging_conf):
12+
logging.config.dictConfig(logging_conf) # type: ignore
13+
client = ZhipuAI(api_key="",disable_token_cache = False) # 填写您自己的APIKey
14+
try:
15+
# 生成request_id
16+
request_id = time.time()
17+
print(f"request_id:{request_id}")
18+
response = client.moderation.moderations.create(
19+
model="moderation",
20+
input={
21+
"type": "text",
22+
"text": "hello world "
23+
}
24+
)
25+
print(response)
26+
27+
except zhipuai.core._errors.APIRequestFailedError as err:
28+
print(err)
29+
except zhipuai.core._errors.APIInternalError as err:
30+
print(err)
31+
except zhipuai.core._errors.APIStatusError as err:
32+
print(err)

tests/integration_tests/test_web_search.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def test_web_search(logging_conf):
1515
count=50,
1616
search_domain_filter="finance.sina.com.cn",
1717
search_recency_filter="oneYear",
18-
content_size="high"
18+
content_size="high",
19+
search_intent=True,
1920
)
2021
print(response)
2122

zhipuai/_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
self.assistant = api_resource.Assistant(self)
6868
self.web_search = api_resource.WebSearchApi(self)
6969
self.audio = api_resource.audio.Audio(self)
70+
self.moderation = api_resource.moderation.Moderation(self)
7071

7172
@property
7273
@override

zhipuai/api_resource/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
Audio
3838
)
3939

40+
from .moderation import (
41+
Moderation
42+
)
43+
4044
from .web_search import (
4145
WebSearchApi
4246
)
@@ -55,5 +59,6 @@
5559
'Knowledge',
5660
'Tools',
5761
'Assistant',
58-
'Audio'
59-
]
62+
'Audio',
63+
'Moderation'
64+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from .moderation import (
2+
Moderation
3+
)
4+
5+
__all__ = [
6+
'Moderation'
7+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import TYPE_CHECKING
2+
3+
from .moderations import Moderations
4+
from ...core import BaseAPI, cached_property
5+
6+
__all__ = ["Moderation"]
7+
class Moderation(BaseAPI):
8+
@cached_property
9+
def moderations(self) -> Moderations:
10+
return Moderations(self._client)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from __future__ import annotations
2+
3+
from typing import Union, List, TYPE_CHECKING, Dict
4+
5+
import logging
6+
from ...core import BaseAPI, deepcopy_minimal
7+
from ...types.moderation.moderation_completion import Completion
8+
9+
10+
logger = logging.getLogger(__name__)
11+
12+
if TYPE_CHECKING:
13+
from ..._client import ZhipuAI
14+
15+
16+
class Moderations(BaseAPI):
17+
def __init__(self, client: "ZhipuAI") -> None:
18+
super().__init__(client)
19+
20+
def create(
21+
self,
22+
*,
23+
model: str,
24+
input: Union[str, List[str], Dict],
25+
) -> Completion:
26+
27+
body = deepcopy_minimal({
28+
"model": model,
29+
"input": input
30+
})
31+
return self._post(
32+
"/moderations",
33+
body=body,
34+
cast_type=Completion
35+
)
36+
37+

zhipuai/api_resource/web_search/web_search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def web_search(
3838
search_domain_filter: Optional[str] | NotGiven = NOT_GIVEN,
3939
search_recency_filter: Optional[str] | NotGiven = NOT_GIVEN,
4040
content_size: Optional[str] | NotGiven = NOT_GIVEN,
41+
search_intent: Optional[bool] | NotGiven = NOT_GIVEN,
4142
extra_headers: Headers | None = None,
4243
extra_body: Body | None = None,
4344
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
@@ -54,6 +55,7 @@ def web_search(
5455
"search_domain_filter": search_domain_filter,
5556
"search_recency_filter": search_recency_filter,
5657
"content_size": content_size,
58+
"search_intent": search_intent,
5759
})
5860
return self._post(
5961
"/web_search",

0 commit comments

Comments
 (0)