Skip to content

Commit 7ff857c

Browse files
authored
Merge pull request #58 from rmkraus/rkraus/fix-error-chat-response-helper
fix: add missing chat error response helper
2 parents 6628201 + d5f10ca commit 7ff857c

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/api/routers/chat.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,34 @@ def _create_fallback_chat_response(
517517
)
518518

519519

520+
def _create_error_chat_response(
521+
user_message: str,
522+
error_message: str,
523+
error_type: str,
524+
session_id: str,
525+
confidence: float,
526+
) -> ChatResponse:
527+
"""Create a standardized ChatResponse for handled chat errors."""
528+
suggestions = [
529+
"Try rephrasing your question",
530+
"Try again in a moment",
531+
"Contact support if the issue persists",
532+
]
533+
return ChatResponse(
534+
reply=user_message,
535+
route="error",
536+
intent="error",
537+
session_id=session_id,
538+
context={
539+
"error": error_message,
540+
"error_type": error_type,
541+
"suggestions": suggestions,
542+
},
543+
confidence=confidence,
544+
recommendations=suggestions,
545+
)
546+
547+
520548
def _create_safety_violation_response(
521549
violations: List[str],
522550
confidence: float,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""Regression tests for chat router private helper wiring."""
17+
18+
import ast
19+
import unittest
20+
from pathlib import Path
21+
22+
23+
CHAT_ROUTER_PATH = Path(__file__).resolve().parents[2] / "src" / "api" / "routers" / "chat.py"
24+
25+
26+
class ChatRouterPrivateHelperTests(unittest.TestCase):
27+
def test_called_create_helpers_are_defined(self) -> None:
28+
"""Ensure refactors do not leave runtime-only missing helper errors behind."""
29+
tree = ast.parse(CHAT_ROUTER_PATH.read_text())
30+
defined_helpers = set()
31+
called_helpers = set()
32+
33+
for node in ast.walk(tree):
34+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name.startswith("_create_"):
35+
defined_helpers.add(node.name)
36+
elif isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id.startswith("_create_"):
37+
called_helpers.add(node.func.id)
38+
39+
self.assertLessEqual(called_helpers, defined_helpers)
40+
41+
42+
if __name__ == "__main__":
43+
unittest.main()

0 commit comments

Comments
 (0)