mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-28 05:07:14 +00:00
perf: claude 的接口异常处理
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
|
import traceback
|
||||||
|
|
||||||
import anthropic
|
import anthropic
|
||||||
|
|
||||||
@@ -62,9 +63,20 @@ class AnthropicMessages(api.LLMAPIRequester):
|
|||||||
|
|
||||||
args["messages"] = req_messages
|
args["messages"] = req_messages
|
||||||
|
|
||||||
resp = await self.client.messages.create(**args)
|
try:
|
||||||
|
|
||||||
yield llm_entities.Message(
|
resp = await self.client.messages.create(**args)
|
||||||
content=resp.content[0].text,
|
|
||||||
role=resp.role
|
yield llm_entities.Message(
|
||||||
)
|
content=resp.content[0].text,
|
||||||
|
role=resp.role
|
||||||
|
)
|
||||||
|
except anthropic.AuthenticationError as e:
|
||||||
|
raise errors.RequesterError(f'api-key 无效: {e.message}')
|
||||||
|
except anthropic.BadRequestError as e:
|
||||||
|
raise errors.RequesterError(str(e.message))
|
||||||
|
except anthropic.NotFoundError as e:
|
||||||
|
if 'model: ' in str(e):
|
||||||
|
raise errors.RequesterError(f'模型无效: {e.message}')
|
||||||
|
else:
|
||||||
|
raise errors.RequesterError(f'请求地址无效: {e.message}')
|
||||||
@@ -2,4 +2,4 @@ class RequesterError(Exception):
|
|||||||
"""Base class for all Requester errors."""
|
"""Base class for all Requester errors."""
|
||||||
|
|
||||||
def __init__(self, message: str):
|
def __init__(self, message: str):
|
||||||
super().__init__("模型请求失败: "+message)
|
super().__init__("模型请求失败: "+message)
|
||||||
|
|||||||
Reference in New Issue
Block a user