最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python - FastAPI Small Talk Greeting Detection Returning Empty Response in TST Environment - Stack Overflow

matteradmin0PV0评论

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"""
#### **
Post a comment

comment list (0)

  1. No comments so far