Restore /facts endpoint and maintain all MCP Server functionality
This commit is contained in:
parent
ec756240b1
commit
64e81869ea
@ -325,6 +325,59 @@ def update_company_facts():
|
||||
"facts": facts
|
||||
})
|
||||
|
||||
# Restore the original /facts endpoint
|
||||
@app.route("/facts", methods=["POST"])
|
||||
def get_facts():
|
||||
"""
|
||||
Get the best set of facts about a question
|
||||
"""
|
||||
data = request.get_json()
|
||||
question = data.get("question")
|
||||
|
||||
if not question:
|
||||
return jsonify({"error": "Missing 'question' in request body"}), 400
|
||||
|
||||
# Query ChromaDB for relevant articles
|
||||
results = query_chroma(question, n_results=10)
|
||||
|
||||
if "error" in results:
|
||||
return jsonify({"error": results["error"]}), 500
|
||||
|
||||
# Process results to create diverse article set
|
||||
mcp_results = []
|
||||
for doc, score, meta in zip(
|
||||
results.get("documents", [[]])[0],
|
||||
results.get("distances", [[]])[0],
|
||||
results.get("metadatas", [[]])[0]):
|
||||
mcp_results.append({
|
||||
"document": doc,
|
||||
"score": float(score),
|
||||
"metadata": meta
|
||||
})
|
||||
|
||||
# Apply diversity filtering
|
||||
diverse_results = get_diverse_articles(mcp_results, 5)
|
||||
|
||||
# Combine with company facts if question mentions a company
|
||||
company_facts_result = {}
|
||||
question_lower = question.lower()
|
||||
|
||||
# Check if question mentions any known company
|
||||
for company_name in company_facts.keys():
|
||||
if company_name.lower() in question_lower:
|
||||
company_facts_result = company_facts[company_name]
|
||||
break
|
||||
|
||||
# Return combined results
|
||||
response_data = {
|
||||
"question": question,
|
||||
"articles": diverse_results,
|
||||
"company_facts": company_facts_result,
|
||||
"timestamp": datetime.now().isoformat()
|
||||
}
|
||||
|
||||
return jsonify(response_data)
|
||||
|
||||
@app.route("/health", methods=["GET"])
|
||||
def health():
|
||||
"""Health check endpoint"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user