mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-24 14:44:46 +08:00
refactor: human feedback doesn't need to check enough context (#423)
This commit is contained in:
@@ -186,8 +186,6 @@ def human_feedback_node(
|
|||||||
plan_iterations += 1
|
plan_iterations += 1
|
||||||
# parse the plan
|
# parse the plan
|
||||||
new_plan = json.loads(current_plan)
|
new_plan = json.loads(current_plan)
|
||||||
if new_plan["has_enough_context"]:
|
|
||||||
goto = "reporter"
|
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
logger.warning("Planner response is not a valid JSON")
|
logger.warning("Planner response is not a valid JSON")
|
||||||
if plan_iterations > 1: # the plan_iterations is increased before this check
|
if plan_iterations > 1: # the plan_iterations is increased before this check
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ def mock_state_base():
|
|||||||
return {
|
return {
|
||||||
"current_plan": json.dumps(
|
"current_plan": json.dumps(
|
||||||
{
|
{
|
||||||
"has_enough_context": True,
|
"has_enough_context": False,
|
||||||
"title": "Test Plan",
|
"title": "Test Plan",
|
||||||
"thought": "Test Thought",
|
"thought": "Test Thought",
|
||||||
"steps": [],
|
"steps": [],
|
||||||
@@ -417,9 +417,9 @@ def test_human_feedback_node_auto_accepted(monkeypatch, mock_state_base):
|
|||||||
state["auto_accepted_plan"] = True
|
state["auto_accepted_plan"] = True
|
||||||
result = human_feedback_node(state)
|
result = human_feedback_node(state)
|
||||||
assert isinstance(result, Command)
|
assert isinstance(result, Command)
|
||||||
assert result.goto == "reporter"
|
assert result.goto == "research_team"
|
||||||
assert result.update["plan_iterations"] == 1
|
assert result.update["plan_iterations"] == 1
|
||||||
assert result.update["current_plan"]["has_enough_context"] is True
|
assert result.update["current_plan"]["has_enough_context"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_human_feedback_node_edit_plan(monkeypatch, mock_state_base):
|
def test_human_feedback_node_edit_plan(monkeypatch, mock_state_base):
|
||||||
@@ -441,9 +441,9 @@ def test_human_feedback_node_accepted(monkeypatch, mock_state_base):
|
|||||||
with patch("src.graph.nodes.interrupt", return_value="[ACCEPTED] Looks good!"):
|
with patch("src.graph.nodes.interrupt", return_value="[ACCEPTED] Looks good!"):
|
||||||
result = human_feedback_node(state)
|
result = human_feedback_node(state)
|
||||||
assert isinstance(result, Command)
|
assert isinstance(result, Command)
|
||||||
assert result.goto == "reporter"
|
assert result.goto == "research_team"
|
||||||
assert result.update["plan_iterations"] == 1
|
assert result.update["plan_iterations"] == 1
|
||||||
assert result.update["current_plan"]["has_enough_context"] is True
|
assert result.update["current_plan"]["has_enough_context"] is False
|
||||||
|
|
||||||
|
|
||||||
def test_human_feedback_node_invalid_interrupt(monkeypatch, mock_state_base):
|
def test_human_feedback_node_invalid_interrupt(monkeypatch, mock_state_base):
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ def dummy_conf():
|
|||||||
|
|
||||||
|
|
||||||
def test_get_env_llm_conf(monkeypatch):
|
def test_get_env_llm_conf(monkeypatch):
|
||||||
|
# Clear any existing environment variables that might interfere
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__API_KEY", raising=False)
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__BASE_URL", raising=False)
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__MODEL", raising=False)
|
||||||
|
|
||||||
monkeypatch.setenv("BASIC_MODEL__API_KEY", "env_key")
|
monkeypatch.setenv("BASIC_MODEL__API_KEY", "env_key")
|
||||||
monkeypatch.setenv("BASIC_MODEL__BASE_URL", "http://env")
|
monkeypatch.setenv("BASIC_MODEL__BASE_URL", "http://env")
|
||||||
conf = llm._get_env_llm_conf("basic")
|
conf = llm._get_env_llm_conf("basic")
|
||||||
@@ -36,6 +41,9 @@ def test_get_env_llm_conf(monkeypatch):
|
|||||||
|
|
||||||
|
|
||||||
def test_create_llm_use_conf_merges_env(monkeypatch, dummy_conf):
|
def test_create_llm_use_conf_merges_env(monkeypatch, dummy_conf):
|
||||||
|
# Clear any existing environment variables that might interfere
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__BASE_URL", raising=False)
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__MODEL", raising=False)
|
||||||
monkeypatch.setenv("BASIC_MODEL__API_KEY", "env_key")
|
monkeypatch.setenv("BASIC_MODEL__API_KEY", "env_key")
|
||||||
result = llm._create_llm_use_conf("basic", dummy_conf)
|
result = llm._create_llm_use_conf("basic", dummy_conf)
|
||||||
assert isinstance(result, DummyChatOpenAI)
|
assert isinstance(result, DummyChatOpenAI)
|
||||||
@@ -43,12 +51,22 @@ def test_create_llm_use_conf_merges_env(monkeypatch, dummy_conf):
|
|||||||
assert result.kwargs["base_url"] == "http://test"
|
assert result.kwargs["base_url"] == "http://test"
|
||||||
|
|
||||||
|
|
||||||
def test_create_llm_use_conf_invalid_type(dummy_conf):
|
def test_create_llm_use_conf_invalid_type(monkeypatch, dummy_conf):
|
||||||
|
# Clear any existing environment variables that might interfere
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__API_KEY", raising=False)
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__BASE_URL", raising=False)
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__MODEL", raising=False)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
llm._create_llm_use_conf("unknown", dummy_conf)
|
llm._create_llm_use_conf("unknown", dummy_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_create_llm_use_conf_empty_conf(monkeypatch):
|
def test_create_llm_use_conf_empty_conf(monkeypatch):
|
||||||
|
# Clear any existing environment variables that might interfere
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__API_KEY", raising=False)
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__BASE_URL", raising=False)
|
||||||
|
monkeypatch.delenv("BASIC_MODEL__MODEL", raising=False)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
llm._create_llm_use_conf("basic", {})
|
llm._create_llm_use_conf("basic", {})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user