fix(wizard): inject profile_so_far context into AI interview LLM prompt
This commit is contained in:
parent
6327a4cdd9
commit
6d1edff1b9
2 changed files with 41 additions and 1 deletions
15
dev-api.py
15
dev-api.py
|
|
@ -4581,7 +4581,20 @@ def wizard_ai_interview(request: WizardInterviewRequest):
|
||||||
else:
|
else:
|
||||||
conversation_lines.append(f"Assistant: {content}")
|
conversation_lines.append(f"Assistant: {content}")
|
||||||
|
|
||||||
prompt = "\n".join(conversation_lines) if conversation_lines else "User: (starting conversation)"
|
history_block = "\n".join(conversation_lines) if conversation_lines else "User: (starting conversation)"
|
||||||
|
|
||||||
|
# Build profile summary to give LLM context about what's already known
|
||||||
|
if request.profile_so_far:
|
||||||
|
gathered = ", ".join(
|
||||||
|
f"{k}={repr(v)}"
|
||||||
|
for k, v in request.profile_so_far.items()
|
||||||
|
if v not in (None, "", [], {})
|
||||||
|
)
|
||||||
|
profile_context = f"\n\n[Already gathered: {gathered}]" if gathered else ""
|
||||||
|
else:
|
||||||
|
profile_context = ""
|
||||||
|
|
||||||
|
prompt = history_block + profile_context
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from scripts.llm_router import LLMRouter
|
from scripts.llm_router import LLMRouter
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,33 @@ class TestWizardAIInterviewLLM:
|
||||||
assert "I am Alex" in prompt
|
assert "I am Alex" in prompt
|
||||||
assert "alex@test.com" in prompt
|
assert "alex@test.com" in prompt
|
||||||
|
|
||||||
|
def test_profile_so_far_injected_into_prompt(self, client):
|
||||||
|
"""profile_so_far fields must appear in the prompt sent to the LLM."""
|
||||||
|
llm_reply = json.dumps({"reply": "Got it!", "extracted_fields": {}, "complete": False})
|
||||||
|
captured_calls = []
|
||||||
|
with patch("dev_api._get_effective_tier", return_value="paid"):
|
||||||
|
with patch("app.wizard.tiers.has_configured_llm", return_value=True):
|
||||||
|
with patch("scripts.llm_router.LLMRouter") as mock_cls:
|
||||||
|
mock_cls.return_value.complete.side_effect = (
|
||||||
|
lambda prompt, system=None: (captured_calls.append(prompt) or llm_reply)
|
||||||
|
)
|
||||||
|
client.post(
|
||||||
|
"/api/wizard/ai/interview",
|
||||||
|
json={
|
||||||
|
"history": [
|
||||||
|
{"role": "user", "content": "I am Alex"},
|
||||||
|
],
|
||||||
|
"profile_so_far": {
|
||||||
|
"name": "Alex Rivera",
|
||||||
|
"email": "alex@example.com",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert len(captured_calls) == 1
|
||||||
|
prompt = captured_calls[0]
|
||||||
|
assert "Alex Rivera" in prompt
|
||||||
|
assert "alex@example.com" in prompt
|
||||||
|
|
||||||
def test_llm_error_returns_500(self, client):
|
def test_llm_error_returns_500(self, client):
|
||||||
"""If LLM raises, the endpoint returns 500."""
|
"""If LLM raises, the endpoint returns 500."""
|
||||||
with patch("dev_api._get_effective_tier", return_value="paid"):
|
with patch("dev_api._get_effective_tier", return_value="paid"):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue