I have implemented a greeting detection logic in my FastAPI application, which works correctly when tested via Postman but fails to return any response in the TST (Test) environment. The logic checks if a user query contains a greeting by comparing it with a predefined list of greeting keywords. If a match is found, it should return a structured response with a greeting message. However, in the TST environment, the function always returns an empty response and proceeds to the next step in the query handling process.
I have verified that the greeting_keywords list is correctly loaded in both environments. When tested in Postman, the API correctly detects greetings like "Hello" or "Hi" and returns the expected response. However, in TST, even with the same input queries, the function does not detect greetings and does not trigger the expected response. Debugging logs indicate that the function does not identify any greeting, but there are no errors in the logs, and the API continues executing the next steps.
The utility_greeting.py
import re
from small_talk_flow import greeting_keywords
def detect_greeting(query):
"""Detects if the query is a greeting and returns an appropriate response."""
query_lower = query.lower().strip()
print(f"Received Query: {query_lower}") # Debugging
for greeting in greeting_keywords:
if greeting in query_lower: # ✅ More flexible check
greeting_response = greeting_keywords[greeting]
print(f"Greeting Matched: {greeting} -> {greeting_response}") # Debugging
return {
"response": greeting_response,
"intent": "Greeting",
"entity": ["No Entity Detected"],
"search_results": ["No Search Results Found"]
}
print("No Greeting Detected") # Debugging
return None
# Build the final markdown summary
def build_greeting_markdown(response_data):
"""Formats the greeting response as a markdown summary."""
markdown_summary = f"""
#### **