Skip to content

Commit 732dab0

Browse files
authored
Merge pull request #63 from yuvalluria/fix/priority-extraction-from-natural-language
fix: Update PRIORITIES UI from LLM-extracted priorities
2 parents 9288431 + 41f0d14 commit 732dab0

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

backend/src/llm/prompts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ def build_intent_extraction_prompt(user_message: str, conversation_history: list
8585
- "summarize document" or "summarization" → use_case: summarization_short or long_document_summarization
8686
8787
Priority extraction (for scoring weights - use "medium" as baseline, adjust based on context):
88-
- accuracy_priority: "high" if accuracy/quality seems important for the use case, "low" if user indicates good-enough is fine
89-
- cost_priority: Default to "medium". Only set "high" if user explicitly mentions budget constraints or cost sensitivity. Only set "low" if user explicitly says cost doesn't matter or budget is unlimited.
90-
- latency_priority: "high" if the use case requires fast responses (e.g., real-time, interactive), "low" if async/batch is acceptable
91-
- complexity_priority: "high" if user wants simple deployment, "low" if they're okay with complex setups
92-
Explicit user statements override inferences (e.g., "cost is critical" → cost_priority: high)
88+
- accuracy_priority: "high" if user mentions accuracy matters, quality is important, accuracy is critical, best model, or top quality. "low" if user says good enough or accuracy less important.
89+
- cost_priority: "high" if user mentions cost-effective, cost-sensitive, budget constrained, minimize cost, cost is important, or budget is tight. "low" if user says cost doesn't matter or budget is unlimited. Default to "medium" if not mentioned.
90+
- latency_priority: "high" if the use case requires fast responses (e.g., real-time, interactive, instant). "low" if async/batch is acceptable.
91+
- complexity_priority: "high" if user wants simple deployment, easy setup. "low" if they're okay with complex setups.
92+
IMPORTANT: Explicit user statements override inferences (e.g., "cost-effective preferred" → cost_priority: high)
9393
9494
{INTENT_EXTRACTION_SCHEMA}
9595
"""

ui/app.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,15 +2752,17 @@ def mock_extraction(user_input: str) -> dict:
27522752
complexity_priority = "medium"
27532753

27542754
# Accuracy priority detection
2755-
if any(kw in text_lower for kw in ["accuracy is important", "quality matters", "best model",
2755+
if any(kw in text_lower for kw in ["accuracy is important", "accuracy matters", "accuracy is critical",
2756+
"quality matters", "quality is critical", "best model",
27562757
"highest accuracy", "accuracy critical", "top quality"]):
27572758
accuracy_priority = "high"
27582759
elif any(kw in text_lower for kw in ["accuracy less important", "good enough", "accuracy not critical"]):
27592760
accuracy_priority = "low"
27602761

27612762
# Cost priority detection
2762-
if any(kw in text_lower for kw in ["cost is important", "budget constrained", "cost-efficient",
2763-
"cost critical", "minimize cost", "budget is tight"]):
2763+
if any(kw in text_lower for kw in ["cost is important", "cost-effective", "cost effective",
2764+
"budget constrained", "cost-efficient", "cost critical",
2765+
"minimize cost", "budget is tight", "cost sensitive"]):
27642766
cost_priority = "high"
27652767
elif any(kw in text_lower for kw in ["not cost sensitive", "budget flexible", "money not an issue",
27662768
"cost doesn't matter"]):
@@ -4716,7 +4718,20 @@ def get_weight_for_priority(dimension: str, priority_level: str) -> int:
47164718
# Get extraction result to check for LLM-detected priorities
47174719
extraction = st.session_state.get('extraction_result', {})
47184720

4719-
# Initialize session state for priorities if not set
4721+
# Check if new extraction is available - force update priorities from LLM
4722+
# This ensures "accuracy matters" in user input updates the UI dropdowns
4723+
if st.session_state.get('new_extraction_available', False):
4724+
st.session_state.accuracy_priority = extraction.get('accuracy_priority', 'medium')
4725+
st.session_state.cost_priority = extraction.get('cost_priority', 'medium')
4726+
st.session_state.latency_priority = extraction.get('latency_priority', 'medium')
4727+
st.session_state.weight_accuracy = get_weight_for_priority("accuracy", st.session_state.accuracy_priority)
4728+
st.session_state.weight_cost = get_weight_for_priority("cost", st.session_state.cost_priority)
4729+
st.session_state.weight_latency = get_weight_for_priority("latency", st.session_state.latency_priority)
4730+
st.session_state.new_extraction_available = False # Clear flag after processing
4731+
logger.info(f"Updated priorities from new extraction: accuracy={st.session_state.accuracy_priority}, "
4732+
f"cost={st.session_state.cost_priority}, latency={st.session_state.latency_priority}")
4733+
4734+
# Initialize session state for priorities if not set (first load)
47204735
if 'accuracy_priority' not in st.session_state:
47214736
st.session_state.accuracy_priority = extraction.get('accuracy_priority', 'medium')
47224737
if 'cost_priority' not in st.session_state:
@@ -5365,6 +5380,10 @@ def clear_dialog_states():
53655380
f"cost={st.session_state.cost_priority}, latency={st.session_state.latency_priority}")
53665381
logger.info(f"Initialized weights: accuracy={st.session_state.weight_accuracy}, "
53675382
f"cost={st.session_state.weight_cost}, latency={st.session_state.weight_latency}")
5383+
5384+
# Set flag to signal PRIORITIES UI to update from this new extraction
5385+
st.session_state.new_extraction_available = True
5386+
53685387
st.session_state.used_priority = extraction.get("priority", priority)
53695388
st.session_state.detected_use_case = extraction.get("use_case", "chatbot_conversational")
53705389
progress_bar.progress(100, text="Ready!")

0 commit comments

Comments
 (0)