Compare commits

..

5 Commits

Author SHA1 Message Date
laundry ba6198f3ec test: fix unit test error
Change-Id: I3dd7a6179132e5497a30ada443d88de0c47af3d4
2025-05-20 11:59:00 +08:00
laundry 28a01dfe0e test: fix unit test error
Change-Id: If4c4cd10673e76a30945674c7cda198aeabf28d0
2025-05-20 11:58:39 +08:00
laundry 3b1db26507 test: fix test error
Change-Id: I3997dc53a2cfaa35501a1fbda5902ee15528124e
2025-05-19 15:47:08 +08:00
laundry e927b556d6 test: add background node unit test
Change-Id: I9aabcf02ff04fda40c56f3ea22abe6b8f93bf9b6
2025-05-19 15:36:24 +08:00
laundry c2b8dd8e6a test: add background node unit test
Change-Id: Ia99f5a1687464387dcb01bbee04deaa371c6e490
2025-05-19 15:33:42 +08:00
4 changed files with 19 additions and 32 deletions
-1
View File
@@ -11,7 +11,6 @@ static/browser_history/*.gif
# Virtual environments
.venv
venv/
# Environment variables
.env
+11 -25
View File
@@ -7,8 +7,7 @@ Server script for running the DeerFlow API.
import argparse
import logging
import signal
import sys
import uvicorn
# Configure logging
@@ -19,17 +18,6 @@ logging.basicConfig(
logger = logging.getLogger(__name__)
def handle_shutdown(signum, frame):
"""Handle graceful shutdown on SIGTERM/SIGINT"""
logger.info("Received shutdown signal. Starting graceful shutdown...")
sys.exit(0)
# Register signal handlers
signal.signal(signal.SIGTERM, handle_shutdown)
signal.signal(signal.SIGINT, handle_shutdown)
if __name__ == "__main__":
# Parse command line arguments
parser = argparse.ArgumentParser(description="Run the DeerFlow API server")
@@ -62,18 +50,16 @@ if __name__ == "__main__":
# Determine reload setting
reload = False
# Command line arguments override defaults
if args.reload:
reload = True
try:
logger.info(f"Starting DeerFlow API server on {args.host}:{args.port}")
uvicorn.run(
"src.server:app",
host=args.host,
port=args.port,
reload=reload,
log_level=args.log_level,
)
except Exception as e:
logger.error(f"Failed to start server: {str(e)}")
sys.exit(1)
logger.info("Starting DeerFlow API server")
uvicorn.run(
"src.server:app",
host=args.host,
port=args.port,
reload=reload,
log_level=args.log_level,
)
+2 -2
View File
@@ -50,10 +50,10 @@ def background_investigation_node(
logger.info("background investigation node is running.")
configurable = Configuration.from_runnable_config(config)
query = state["messages"][-1].content
if SELECTED_SEARCH_ENGINE == SearchEngine.TAVILY.value:
if SELECTED_SEARCH_ENGINE == SearchEngine.TAVILY:
searched_content = LoggedTavilySearch(
max_results=configurable.max_search_results
).invoke(query)
).invoke({"query": query})
background_investigation_results = None
if isinstance(searched_content, list):
background_investigation_results = [
+6 -4
View File
@@ -68,7 +68,7 @@ def mock_web_search_tool():
yield mock
@pytest.mark.parametrize("search_engine", [SearchEngine.TAVILY.value, "other"])
@pytest.mark.parametrize("search_engine", [SearchEngine.TAVILY, "other"])
def test_background_investigation_node_tavily(
mock_state,
mock_tavily_search,
@@ -93,8 +93,10 @@ def test_background_investigation_node_tavily(
results = json.loads(update["background_investigation_results"])
assert isinstance(results, list)
if search_engine == SearchEngine.TAVILY.value:
mock_tavily_search.return_value.invoke.assert_called_once_with("test query")
if search_engine == SearchEngine.TAVILY:
mock_tavily_search.return_value.invoke.assert_called_once_with(
{"query": "test query"}
)
assert len(results) == 2
assert results[0]["title"] == "Test Title 1"
assert results[0]["content"] == "Test Content 1"
@@ -109,7 +111,7 @@ def test_background_investigation_node_malformed_response(
mock_state, mock_tavily_search, patch_config_from_runnable_config, mock_config
):
"""Test background_investigation_node with malformed Tavily response"""
with patch("src.graph.nodes.SELECTED_SEARCH_ENGINE", SearchEngine.TAVILY.value):
with patch("src.graph.nodes.SELECTED_SEARCH_ENGINE", SearchEngine.TAVILY):
# Mock a malformed response
mock_tavily_search.return_value.invoke.return_value = "invalid response"