Skip to content

Commit ad260ed

Browse files
committed
Update mock_server.py
1 parent 0193ac9 commit ad260ed

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

tests/mock_server.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Parameters(BaseModel):
132132

133133
class GenerationRequest(BaseModel):
134134
model: str
135-
input: InputData
135+
input: Optional[InputData] = None
136136
parameters: Optional[Parameters] = Field(default_factory=Parameters)
137137

138138

@@ -180,6 +180,25 @@ async def generate(
180180
initial_request_id: str,
181181
force_stream: bool = False,
182182
):
183+
# --- Input Content Validation (Case: testNonInputByCode) ---
184+
has_input = req_data.input is not None
185+
has_content = False
186+
if has_input:
187+
has_content = (
188+
bool(req_data.input.messages)
189+
or bool(req_data.input.prompt)
190+
or bool(req_data.input.history)
191+
)
192+
193+
if not has_input or not has_content:
194+
return JSONResponse(
195+
status_code=400,
196+
content={
197+
"code": "InvalidParameter",
198+
"message": '<400> InternalError.Algo.InvalidParameter: Either "prompt" or "messages" must exist and cannot both be none',
199+
},
200+
)
201+
183202
params = req_data.parameters
184203

185204
# --- Validation Logic ---
@@ -668,6 +687,16 @@ async def validation_exception_handler(request, exc):
668687
loc = err.get("loc", [])
669688
param_name = loc[-1] if loc else "unknown"
670689

690+
# --- Handle Missing Model (Case: testEmptyMsgByCode) ---
691+
if "model" in loc and err.get("type") == "missing":
692+
return JSONResponse(
693+
status_code=400,
694+
content={
695+
"code": "BadRequest.EmptyModel",
696+
"message": 'Required parameter "model" missing from request.'
697+
},
698+
)
699+
671700
if param_name == "content":
672701
if "valid string" in error_msg or "str" in error_msg:
673702
return JSONResponse(

0 commit comments

Comments
 (0)