Files
ZNJJ-api-server/src/schemas/models.py
Xin Wang 3187713bfe Enhance client mode handling in ProcessRequest_chat
- Introduced a normalization function for client mode to default to "direct" when input is empty or None.
- Updated the clientMode field to use a new type with BeforeValidator for improved validation.
- Added a test to ensure empty client mode inputs correctly default to "direct".
2026-07-29 10:02:35 +08:00

68 lines
2.2 KiB
Python

from pydantic import BaseModel, BeforeValidator, Field
from typing import Annotated, Any, Literal, Optional
ClientMode = Literal["direct", "browser_addon"]
def normalize_client_mode(value: Any) -> Any:
if value is None or (isinstance(value, str) and value.strip() == ""):
return "direct"
return value
NormalizedClientMode = Annotated[ClientMode, BeforeValidator(normalize_client_mode)]
class ProcessRequest_chat(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
text: str = Field(...)
clientMode: NormalizedClientMode = "direct"
needFormUpdate: bool = False
useTextChunk: bool = False
class ProcessResponse_chat(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
outputText: str = Field(...)
formUpdate: Any = Field(default_factory=dict)
nextStage: str = Field(..., max_length=32)
nextStageCode: str = Field(..., max_length=32)
code: str = Field(..., max_length=4)
msg: Optional[str] = None
class ProcessRequest_get(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
key: str = Field(...)
includeInputInfo: bool = False
class ProcessResponse_get(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
value: str = Field(...)
code: str = Field(..., max_length=4)
msg: Optional[str] = None
class ProcessRequest_set(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
key: str = Field(...)
value: str = Field(...)
includeInputInfo: bool = False
class ProcessResponse_set(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
code: str = Field(..., max_length=4)
msg: Optional[str] = None
class ProcessRequest_delete_session(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
class ProcessResponse_delete_session(BaseModel):
sessionId: str = Field(..., max_length=64)
timeStamp: str = Field(..., max_length=32)
code: str = Field(..., max_length=4)
msg: Optional[str] = None