Jun 30 - Add chat to AI analysis result (content from raw data)

This commit is contained in:
2026-06-30 11:45:22 -04:00
parent 5719bcf06e
commit c5078cc5f8
3 changed files with 41 additions and 11 deletions
+17 -7
View File
@@ -100,7 +100,8 @@ def analyze():
])
analysis_id = save_ai_analysis(
user["id"], ", ".join(file_names), model,
result.get("verdict"), criteria_snap, result.get("summary", "")
result.get("verdict"), criteria_snap, result.get("summary", ""),
document_text=combined,
)
log_action(user["id"], "AI_ANALYSIS", "ai_analysis_log", analysis_id,
f"AI analysis on {len(file_names)} file(s). Verdict: {result.get('verdict')}.")
@@ -472,15 +473,24 @@ def chat():
if not api_key:
return jsonify({"error": "Groq API key is not configured."}), 400
model = get_setting("groq.model", GROQ_MODELS[0])
summary = (record.get("summary_text") or "")[:8000]
model = get_setting("groq.model", GROQ_MODELS[0])
# Prefer raw document text so the AI can answer questions from source material.
# Fall back to the stored summary for analyses run before this feature was added.
raw_text = (record.get("document_text") or "").strip()
if raw_text:
context_label = "ORIGINAL DOCUMENT CONTENT"
context_body = raw_text[:12000]
else:
context_label = "ANALYZED DOCUMENT SUMMARY"
context_body = (record.get("summary_text") or "")[:8000]
system_msg = (
"You are a government procurement analyst assistant. "
"The user has questions about a solicitation document that has already been analyzed. "
"Answer questions based solely on the analysis summary below. "
"If the information is not in the summary, say so clearly. Be concise and direct.\n\n"
"## ANALYZED DOCUMENT SUMMARY\n\n" + summary
"The user has questions about a solicitation document. "
"Answer based solely on the document content provided below. "
"If the information is not present, say so clearly. Be concise and direct.\n\n"
f"## {context_label}\n\n" + context_body
)
# Sanitize and cap conversation history at 20 turns