Skip to content

Commit 13a9dd2

Browse files
committed
关于readme的错误
#22
1 parent 18b29b2 commit 13a9dd2

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

README.md

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -170,46 +170,43 @@ test_completions_charglm()
170170

171171
### 异常处理
172172

173-
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `openai.APIConnectionError` is raised.
174-
175-
When the API returns a non-success status code (that is, 4xx or 5xx
176-
response), a subclass of `openai.APIStatusError` is raised, containing `status_code` and `response` properties.
177-
178-
All errors inherit from `openai.APIError`.
173+
模块定义了一些统一的参数返回(例如:响应错误,网络超时错误)
179174

175+
业务定义了http错误的响应类 (在接口返回,40x或者50x), 会抛出 `zhipuai.APIStatusError` ,包含 `status_code``response` 属性. 它们都是继承 `zhipuai.APIStatusError`.
176+
其它Exception,属于不可预知的错误
180177
```python
181-
import openai
182-
from openai import OpenAI
183-
184-
client = OpenAI()
185-
178+
from zhipuai import ZhipuAI
179+
import zhipuai
180+
client = ZhipuAI() # 填写您自己的APIKey
186181
try:
187-
client.fine_tunes.create(
188-
training_file="file-XGinujblHPwGLSztz8cPS8XY",
189-
)
190-
except openai.APIConnectionError as e:
191-
print("The server could not be reached")
192-
print(e.__cause__) # an underlying Exception, likely raised within httpx.
193-
except openai.RateLimitError as e:
194-
print("A 429 status code was received; we should back off a bit.")
195-
except openai.APIStatusError as e:
196-
print("Another non-200-range status code was received")
197-
print(e.status_code)
198-
print(e.response)
182+
response = client.chat.completions.create(
183+
model="glm-4", # 填写需要调用的模型名称
184+
messages=[
185+
{"role": "user", "content": "作为一名营销专家,请为我的产品创作一个吸引人的slogan"},
186+
{"role": "assistant", "content": "当然,为了创作一个吸引人的slogan,请告诉我一些关于您产品的信息"},
187+
{"role": "user", "content": "智谱AI开放平台"},
188+
{"role": "assistant", "content": "智启未来,谱绘无限一智谱AI,让创新触手可及!"},
189+
{"role": "user", "content": "创造一个更精准、吸引人的slogan"}
190+
]
191+
)
192+
print(response)
193+
194+
except zhipuai.APIStatusError as err:
195+
print(err)
196+
except zhipuai.APITimeoutError as err:
197+
print(err)
199198
```
200199

201200
Error codes are as followed:
202201

203202
| Status Code | Error Type |
204-
| ----------- | -------------------------- |
205-
| 400 | `BadRequestError` |
206-
| 401 | `AuthenticationError` |
207-
| 403 | `PermissionDeniedError` |
208-
| 404 | `NotFoundError` |
209-
| 422 | `UnprocessableEntityError` |
210-
| 429 | `RateLimitError` |
211-
| >=500 | `InternalServerError` |
212-
| N/A | `APIConnectionError` |
203+
|-------------| -------------------------- |
204+
| 400 | `APIRequestFailedError` |
205+
| 401 | `APIAuthenticationError` |
206+
| 429 | `APIReachLimitError` |
207+
| 500 | `APIInternalError` |
208+
| 503 | `APIServerFlowExceedError` |
209+
| N/A | `APIStatusError` |
213210

214211

215212

0 commit comments

Comments
 (0)