feat: 完成资源接入
This commit is contained in:
@@ -2,12 +2,27 @@
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, ValidationError
|
||||
|
||||
|
||||
class ActionValidationError(BaseModel):
|
||||
action_index: int | None = Field(
|
||||
default=None, ge=0, description="失败动作的下标,从 0 开始,整批错误为 null"
|
||||
)
|
||||
code: Literal["schema_error", "execution_error"]
|
||||
code: Literal["schema_error", "generation_error", "scope_error", "execution_error"]
|
||||
message: str
|
||||
|
||||
|
||||
def schema_errors(error: ValidationError) -> list[ActionValidationError]:
|
||||
errors = []
|
||||
for item in error.errors(include_url=False, include_input=False):
|
||||
location = item["loc"]
|
||||
index = location[1] if len(location) > 1 and type(location[1]) is int else None
|
||||
errors.append(
|
||||
ActionValidationError(
|
||||
action_index=index,
|
||||
code="schema_error",
|
||||
message=f"{' / '.join(map(str, location))}: {item['msg']}",
|
||||
)
|
||||
)
|
||||
return errors
|
||||
|
||||
Reference in New Issue
Block a user