Commit
·
fdc8bbe
1
Parent(s):
7132f6b
fix: Apply CodeRabbit suggestions
Browse files- Remove invalid language field from .coderabbit.yaml config
- Validate temperature before building payload (CodeRabbit suggestion)
- Improve code efficiency by validating inputs early
- .coderabbit.yaml +1 -2
- app/routers/openai_api.py +9 -8
.coderabbit.yaml
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
# CodeRabbit configuration
|
| 2 |
# See: https://docs.coderabbit.ai/configuration
|
| 3 |
-
|
| 4 |
-
language: python
|
| 5 |
|
| 6 |
review:
|
| 7 |
# Enable/disable review
|
|
|
|
| 1 |
# CodeRabbit configuration
|
| 2 |
# See: https://docs.coderabbit.ai/configuration
|
| 3 |
+
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
|
|
|
|
| 4 |
|
| 5 |
review:
|
| 6 |
# Enable/disable review
|
app/routers/openai_api.py
CHANGED
|
@@ -61,22 +61,23 @@ async def chat_completions(body: ChatCompletionRequest):
|
|
| 61 |
content={"error": {"message": "messages list cannot be empty", "type": "invalid_request_error"}}
|
| 62 |
)
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
# Build payload with all supported parameters
|
| 65 |
payload: Dict[str, Any] = {
|
| 66 |
"model": body.model or settings.model,
|
| 67 |
"messages": [m.model_dump() for m in body.messages],
|
| 68 |
-
"temperature":
|
| 69 |
"top_p": body.top_p or 1.0,
|
| 70 |
"stream": body.stream or False,
|
| 71 |
}
|
| 72 |
|
| 73 |
-
# Validate temperature range
|
| 74 |
-
if payload["temperature"] < 0 or payload["temperature"] > 2:
|
| 75 |
-
return JSONResponse(
|
| 76 |
-
status_code=400,
|
| 77 |
-
content={"error": {"message": "temperature must be between 0 and 2", "type": "invalid_request_error"}}
|
| 78 |
-
)
|
| 79 |
-
|
| 80 |
# Add optional max_tokens if provided
|
| 81 |
if body.max_tokens is not None:
|
| 82 |
if body.max_tokens < 1:
|
|
|
|
| 61 |
content={"error": {"message": "messages list cannot be empty", "type": "invalid_request_error"}}
|
| 62 |
)
|
| 63 |
|
| 64 |
+
# Validate temperature range before building payload
|
| 65 |
+
temperature = body.temperature or 0.7
|
| 66 |
+
if temperature < 0 or temperature > 2:
|
| 67 |
+
return JSONResponse(
|
| 68 |
+
status_code=400,
|
| 69 |
+
content={"error": {"message": "temperature must be between 0 and 2", "type": "invalid_request_error"}}
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
# Build payload with all supported parameters
|
| 73 |
payload: Dict[str, Any] = {
|
| 74 |
"model": body.model or settings.model,
|
| 75 |
"messages": [m.model_dump() for m in body.messages],
|
| 76 |
+
"temperature": temperature,
|
| 77 |
"top_p": body.top_p or 1.0,
|
| 78 |
"stream": body.stream or False,
|
| 79 |
}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
# Add optional max_tokens if provided
|
| 82 |
if body.max_tokens is not None:
|
| 83 |
if body.max_tokens < 1:
|