fix: pydantic

This commit is contained in:
Yeuoly 2024-09-19 18:02:24 +08:00
parent 4eaba3049a
commit c472ea6c67
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61
3 changed files with 8 additions and 6 deletions

View File

@ -42,7 +42,8 @@ class RequestInvokeLLM(BaseRequestInvokeModel):
stream: Optional[bool] = False
@field_validator("prompt_messages", mode="before")
def convert_prompt_messages(self, v):
@classmethod
def convert_prompt_messages(cls, v):
if not isinstance(v, list):
raise ValueError("prompt_messages must be a list")

View File

@ -114,7 +114,8 @@ class ToolInvokeMessage(BaseModel):
stream: bool = Field(default=False, description="Whether the variable is streamed")
@field_validator("variable_value", mode="before")
def transform_variable_value(self, value, values) -> Any:
@classmethod
def transform_variable_value(cls, value, values) -> Any:
"""
Only basic types and lists are allowed.
"""
@ -129,7 +130,8 @@ class ToolInvokeMessage(BaseModel):
return value
@field_validator("variable_name", mode="before")
def transform_variable_name(self, value) -> str:
@classmethod
def transform_variable_name(cls, value) -> str:
"""
The variable name must be a string.
"""

View File

@ -245,9 +245,8 @@ class ToolEngine:
+ "you do not need to create it, just tell the user to check it now."
)
elif response.type == ToolInvokeMessage.MessageType.JSON:
result += f"tool response: {
json.dumps(cast(ToolInvokeMessage.JsonMessage, response.message).json_object, ensure_ascii=False)
}."
text = json.dumps(cast(ToolInvokeMessage.JsonMessage, response.message).json_object, ensure_ascii=False)
result += f"tool response: {text}."
else:
result += f"tool response: {response.message}."