1 import logging 2 from flask import Flask, session, request, render_template, jsonify 3 from flask_session import Session 4 from datetime import datetime 5 6 from modules.tools import tool_definitions 7 from modules.llm.ollama_client import ensure_ollama_running, list_models_cached 8 9 app = Flask(__name__) 10 app.config['SESSION_TYPE'] = 'filesystem' 11 app.config['SESSION_FILE_DIR'] = '../flask_session_dir' 12 app.config['SESSION_PERMANENT'] = False 13 Session(app) 14 app.secret_key = "your_secure_random_string_here" 15 16 logging.basicConfig(level=logging.INFO) 17 logger = logging.getLogger(__name__) 18 19 from modules.system_prompts.system_prompts import SYSTEM_PROMPTS 20 21 SYSTEM_PROMPTS = SYSTEM_PROMPTS 22 23 MODE = "COGITO" 24 25 def get_system_prompt(mode: str) -> str: 26 return SYSTEM_PROMPTS.get(mode, SYSTEM_PROMPTS["COGITO"]) 27 28 def init_chat_history(mode: str = "COGITO") -> None: 29 session['chat_history'] = [{"role": "system", "content": get_system_prompt(mode)}] 30 31 @app.route("/") 32 def index(): 33 if 'chat_history' not in session: 34 init_chat_history(MODE) 35 return render_template("index.html", chat_history=session['chat_history']) 36 37 @app.route("/chat", methods=["POST"]) 38 async def chat(): 39 user_message = request.form.get("message", "").strip() 40 logger.info("User ▶ %s", user_message) 41 if not user_message: 42 return jsonify(error="No message provided"), 400 43 44 if 'chat_history' not in session: 45 init_chat_history(MODE) 46 47 session['chat_history'].append({"role": "user", "content": user_message}) 48 chat_history = session['chat_history'] 49 model_name = "huihui_ai/qwen2.5-1m-abliterated:latest" 50 # logger.info(f"Chat History: {chat_history}") 51 # prompt_text = "\n".join([m['content'] for m in chat_history ]) 52 53 from modules.agent.planner import Planner 54 planner = Planner() 55 planner.receive_input(user_message) 56 assistant_text = await planner.process() 57 58 session['chat_history'].append({"role": "assistant", "content": assistant_text}) 59 session.modified = True 60 logger.info("Nova ▶ %s", assistant_text) 61 return jsonify(chat_history=session['chat_history']) 62 63 @app.route("/clear", methods=["POST"]) 64 def clear_history(): 65 init_chat_history(MODE) 66 return jsonify(chat_history=session['chat_history']) 67 68 if __name__ == "__main__": 69 logger.info("Available models: %s", list_models_cached()) 70 app.run(host="localhost", debug=True, port=4141) 71