-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_footer.txt
More file actions
100 lines (88 loc) · 3.52 KB
/
api_footer.txt
File metadata and controls
100 lines (88 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
except Exception as e:
logger.error(f"Report generation error: {e}")
return jsonify({'error': str(e)}), 500
@app.route('/validation/test', methods=['POST'])
@require_api_key
def test_thresholds():
"""Test search quality for a query"""
data = request.get_json() or {}
query = data.get('query', '')
if not query:
return jsonify({'error': 'No query provided'}), 400
try:
# Run search with ultimate system
results = search_system.search(query)
# Validate results
validation = validator.quick_validate(query, results, 0.7)
# Get quality breakdown
quality_analysis = {
'total_results': len(results),
'accepted_answers': sum(1 for r in results if r.get('is_accepted')),
'high_score_answers': sum(1 for r in results if r.get('answer_score', 0) > 100),
'with_code': sum(1 for r in results if r.get('code')),
'avg_similarity': sum(r.get('confidence', 0) for r in results) / len(results) if results else 0,
'avg_score': sum(r.get('answer_score', 0) for r in results) / len(results) if results else 0
}
return jsonify({
'query': query,
'quality_score': validation['score'],
'validation': validation,
'quality_analysis': quality_analysis,
'top_results': results[:5] # Show top 5 results
})
except Exception as e:
logger.error(f"Threshold test error: {e}")
return jsonify({'error': str(e)}), 500
# ERROR HANDLERS
@app.errorhandler(404)
def not_found(e):
return jsonify({'error': 'Endpoint not found'}), 404
@app.errorhandler(500)
def server_error(e):
return jsonify({'error': 'Server error'}), 500
# MAIN
if __name__ == '__main__':
print(f"""
🚀 ULTIMATE STACK OVERFLOW SEARCH API READY!
================================================================================
✅ Database: {"Connected" if db_conn else "Not connected"}
✅ Search System: {"Ready" if search_system.conn else "Not ready"}
✅ FTS5: Enabled
✅ Port: {CONFIG['PORT']}
================================================================================
🔑 Beta Keys:
- 'demo' (100 requests/day)
- Use /register to get your own key
================================================================================
⚡ Features:
- Multi-strategy FTS5 search
- Sub-50ms response times
- Smart query preprocessing
- Result caching
- Quality validation
================================================================================
📊 Search Strategies:
1. Exact error matching
2. Error type + key terms
3. Important words only
4. Fuzzy matching
================================================================================
📧 Questions? Check the docs at the root URL (/)
================================================================================
""")
# Try ngrok if available
try:
from pyngrok import ngrok
public_url = ngrok.connect(
CONFIG['PORT'],
"http",
hostname="terrier-meet-vigorously.ngrok-free.app"
)
print(f"🌐 PUBLIC URL: {public_url}")
print(f"🌐 PUBLIC URL: {public_url}")
print(f"🌐 PUBLIC URL: {public_url}")
print("================================================================================")
except Exception as e:
print(f"Ngrok error: {e}")
pass
app.run(host='0.0.0.0', port=CONFIG['PORT'], debug=False)