Skip to content

Commit 769f8ed

Browse files
committed
参数说明
1 parent 49f87ba commit 769f8ed

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ client = ZhipuAI(
4444
api_key="", # 填写您的 APIKey
4545
)
4646
```
47+
### 客户端网络链接配置
48+
`core/_http_client.py`中,可以配置网络链接的超时时间,重试次数,限制等参数
49+
```python
50+
# 通过 `Timeout` 控制接口`connect` 和 `read` 超时时间,默认为`timeout=300.0, connect=8.0`
51+
ZHIPUAI_DEFAULT_TIMEOUT = httpx.Timeout(timeout=300.0, connect=8.0)
52+
# 通过 `retry` 参数控制重试次数,默认为3次
53+
ZHIPUAI_DEFAULT_MAX_RETRIES = 3
54+
# 通过 `Limits` 控制最大连接数和保持连接数,默认为`max_connections=50, max_keepalive_connections=10`
55+
ZHIPUAI_DEFAULT_LIMITS = httpx.Limits(max_connections=50, max_keepalive_connections=10)
56+
57+
```
58+
同样在`ZhipuAI`入参中可以配置
59+
```python
60+
client = ZhipuAI(
61+
timeout= httpx.Timeout(timeout=300.0, connect=8.0),
62+
max_retries=3,
63+
)
64+
```
65+
4766

4867
### 同步调用
4968

zhipuai/core/_http_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@
5656

5757
from httpx._config import DEFAULT_TIMEOUT_CONFIG as HTTPX_DEFAULT_TIMEOUT
5858
RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
59+
# 通过 `Timeout` 控制接口`connect` 和 `read` 超时时间,默认为`timeout=300.0, connect=8.0`
5960
ZHIPUAI_DEFAULT_TIMEOUT = httpx.Timeout(timeout=300.0, connect=8.0)
61+
# 通过 `retry` 参数控制重试次数,默认为3次
6062
ZHIPUAI_DEFAULT_MAX_RETRIES = 3
63+
# 通过 `Limits` 控制最大连接数和保持连接数,默认为`max_connections=50, max_keepalive_connections=10`
6164
ZHIPUAI_DEFAULT_LIMITS = httpx.Limits(max_connections=50, max_keepalive_connections=10)
6265

6366
INITIAL_RETRY_DELAY = 0.5

0 commit comments

Comments
 (0)