generated from google-gemini/aistudio-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_server.py
More file actions
executable file
·59 lines (46 loc) · 1.67 KB
/
ai_server.py
File metadata and controls
executable file
·59 lines (46 loc) · 1.67 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
#!/bin/env python3
import sys
import os
import time
from flask import Flask, request, jsonify
from flask_cors import CORS
# Add the current directory to sys.path so we can import from ai/
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from ai.nexus_brain import NexusBrain
app = Flask(__name__)
CORS(app)
# Initialize the Brain
print("[SERVER] Initializing Nexus Psychologic Core...")
brain = NexusBrain()
print("[SERVER] Brain Online.")
@app.route('/process', methods=['POST'])
def process_data():
"""
API endpoint that accepts JSON input and returns the Nexus Brain's structured thought process.
"""
try:
data = request.get_json()
input_query = data.get('query', '')
if not input_query:
return jsonify({"error": "No 'query' provided."}), 400
print(f"[SERVER] Processing: {input_query}")
# Use the structured processing method
result = brain.process_structured(input_query)
return jsonify({
"status": "success",
"thoughts": result['thoughts'],
"memory_context": result['memory_context'],
"final_output": result['final_output'],
"learned_concept": result['learned_concept'],
"timestamp": time.time()
})
except Exception as e:
print(f"[SERVER] Error: {e}")
return jsonify({"error": str(e)}), 500
@app.route('/status', methods=['GET'])
def status():
return jsonify({"status": "online", "model": "Nexus-8"})
if __name__ == '__main__':
port = 11435
print(f"[SERVER] Starting Nexus Server on http://127.0.0.1:{port}/")
app.run(debug=True, port=port, host='0.0.0.0')