- Add functionality to add a default dictionary for configuration fields

- Correct entitlement processing
- Remove get_template functionality from ModelVariables, define it directly with LLM model definition in configuration file.
This commit is contained in:
Josako
2025-05-19 14:10:09 +02:00
parent d2a9092f46
commit 28aea85b10
15 changed files with 386 additions and 85 deletions

View File

@@ -1,5 +1,5 @@
from datetime import datetime as dt, timezone as tz, timedelta
from flask import request, redirect, flash, render_template, Blueprint, session, current_app
from flask import request, redirect, flash, render_template, Blueprint, session, current_app, jsonify
from flask_security import roles_accepted, current_user
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy import or_, desc
@@ -395,4 +395,58 @@ def transition_period_status(license_id, period_id):
db.session.rollback()
flash(f'Error updating status: {str(e)}', 'danger')
return redirect(prefixed_url_for('entitlements_bp.view_license_periods', license_id=license_id))
return redirect(prefixed_url_for('entitlements_bp.view_license_periods', license_id=license_id))
@entitlements_bp.route('/active_usage')
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def active_license_usage():
# Retrieve the active license period for the current tenant
tenant_id = session.get('tenant', {}).get('id')
if not tenant_id:
flash('No active or pending license period found for this tenant', 'warning')
return redirect(prefixed_url_for('user_bp.select_tenant'))
active_period = LicensePeriod.query \
.join(License) \
.filter(
License.tenant_id == tenant_id,
LicensePeriod.status.in_([PeriodStatus.ACTIVE, PeriodStatus.PENDING])
).first()
if not active_period:
flash('Geen actieve of pending licentieperiode gevonden voor deze tenant', 'warning')
return render_template('entitlements/view_active_license_usage.html', active_period=None)
# Bereken de percentages voor gebruik
usage_data = {}
if active_period.license_usage:
# Storage percentage
if active_period.max_storage_mb > 0:
storage_used = active_period.license_usage.storage_mb_used or 0.0
usage_data['storage_used_rounded'] = round(storage_used, 2)
usage_data['storage_percent'] = round(storage_used / active_period.max_storage_mb * 100, 2)
else:
usage_data['storage_percent'] = 0.0
# Embedding percentage
if active_period.included_embedding_mb > 0:
embedding_used = active_period.license_usage.embedding_mb_used or 0.0
usage_data['embedding_used_rounded'] = round(embedding_used, 2)
usage_data['embedding_percent'] = round(embedding_used / active_period.included_embedding_mb * 100, 2)
else:
usage_data['embedding_percent'] = 0.0
# Interaction tokens percentage
if active_period.included_interaction_tokens > 0:
interaction_used = active_period.license_usage.interaction_total_tokens_used / 1_000_000 or 0.0
usage_data['interaction_used_rounded'] = round(interaction_used, 2)
usage_data['interaction_percent'] = (
round(interaction_used / active_period.included_interaction_tokens * 100, 2))
else:
usage_data['interaction_percent'] = 0
return render_template('entitlements/view_active_license_usage.html',
active_period=active_period,
usage_data=usage_data)