Add AJAX support to optimize_models endpoint and add CLAUDE.md

- Added jsonify import to admin.py
- optimize_models now returns JSON for AJAX requests (X-Requested-With header)
- Returns structured {status, message} response for success and error cases
- Added CLAUDE.md project configuration file

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 01:00:32 -05:00
parent 0667c31413
commit 41f5719974
2 changed files with 15 additions and 1 deletions

9
CLAUDE.md Normal file
View File

@@ -0,0 +1,9 @@
# Claude Custom Instructions
## Git Workflow
Every time you complete a task or make changes to files, you MUST automatically commit those changes to Git before waiting for the user's next prompt.
### Instructions:
1. Always run `git add .` to stage your changes.
2. Run `git commit -m "Auto-commit: [brief description of what was changed]"`
3. Do not ask for permission to commit, just perform the git commit automatically.

View File

@@ -2,7 +2,7 @@ import os
import json
import shutil
from datetime import datetime, timedelta
from flask import Blueprint, render_template, request, redirect, url_for, flash, session
from flask import Blueprint, render_template, request, redirect, url_for, flash, session, jsonify
from flask_login import login_required, login_user, current_user
from sqlalchemy import func
from web.db import db, User, Project, Run
@@ -195,14 +195,19 @@ def debug_routes():
@login_required
@admin_required
def optimize_models():
is_ajax = request.headers.get('X-Requested-With') == 'XMLHttpRequest'
try:
ai_setup.init_models(force=True)
if ai_models.model_logic:
style_persona.refresh_style_guidelines(ai_models.model_logic)
if is_ajax:
return jsonify({'status': 'ok', 'message': 'AI Models refreshed and Style Guidelines updated.'})
flash("AI Models refreshed and Style Guidelines updated.")
except Exception as e:
if is_ajax:
return jsonify({'status': 'error', 'message': f'Error refreshing models: {e}'}), 500
flash(f"Error refreshing models: {e}")
return redirect(request.referrer or url_for('project.index'))