diff --git a/common/models/entitlements.py b/common/models/entitlements.py index 5eb28dd..d87d63b 100644 --- a/common/models/entitlements.py +++ b/common/models/entitlements.py @@ -95,10 +95,13 @@ class LicenseUsage(db.Model): license_id = db.Column(db.Integer, db.ForeignKey('public.license.id'), nullable=False) tenant_id = db.Column(db.Integer, db.ForeignKey('public.tenant.id'), nullable=False) storage_mb_used = db.Column(db.Integer, default=0) - storage_tokens_used = db.Column(db.Integer, default=0) embedding_mb_used = db.Column(db.Integer, default=0) - embedding_tokens_used = db.Column(db.Integer, default=0) - interaction_tokens_used = db.Column(db.Integer, default=0) + embedding_prompt_tokens_used = db.Column(db.Integer, default=0) + embedding_completion_tokens_used = db.Column(db.Integer, default=0) + embedding_total_tokens_used = db.Column(db.Integer, default=0) + interaction_prompt_tokens_used = db.Column(db.Integer, default=0) + interaction_completion_tokens_used = db.Column(db.Integer, default=0) + interaction_total_tokens_used = db.Column(db.Integer, default=0) period_start_date = db.Column(db.Date, nullable=False) period_end_date = db.Column(db.Date, nullable=False) diff --git a/common/models/user.py b/common/models/user.py index b698450..93b5d4e 100644 --- a/common/models/user.py +++ b/common/models/user.py @@ -64,6 +64,7 @@ class Tenant(db.Model): # Entitlements currency = db.Column(db.String(20), nullable=True) usage_email = db.Column(db.String(255), nullable=True) + storage_dirty = db.Column(db.Boolean, nullable=True, default=False) # Relations users = db.relationship('User', backref='tenant') diff --git a/common/utils/document_utils.py b/common/utils/document_utils.py index 9cdcc65..17783ae 100644 --- a/common/utils/document_utils.py +++ b/common/utils/document_utils.py @@ -12,6 +12,7 @@ import requests from urllib.parse import urlparse, unquote import os from .eveai_exceptions import EveAIInvalidLanguageException, EveAIDoubleURLException, EveAIUnsupportedFileType +from ..models.user import Tenant def create_document_stack(api_input, file, filename, extension, tenant_id): @@ -81,6 +82,8 @@ def create_version_for_document(document, url, language, user_context, user_meta set_logging_information(new_doc_vers, dt.now(tz.utc)) + mark_tenant_storage_dirty(document.tenant_id) + return new_doc_vers @@ -338,3 +341,10 @@ def refresh_document(doc_id): } return refresh_document_with_info(doc_id, api_input) + + +# Function triggered when a document_version is created or updated +def mark_tenant_storage_dirty(tenant_id): + tenant = db.session.query(Tenant).filter_by(id=tenant_id).first() + tenant.storage_dirty = True + db.session.commit() diff --git a/common/utils/eveai_exceptions.py b/common/utils/eveai_exceptions.py index c1f1ee3..fcd54a4 100644 --- a/common/utils/eveai_exceptions.py +++ b/common/utils/eveai_exceptions.py @@ -34,3 +34,10 @@ class EveAIUnsupportedFileType(EveAIException): super().__init__(message, status_code, payload) +class EveAINoLicenseForTenant(EveAIException): + """Raised when no active license for a tenant is provided""" + + def __init__(self, message="No license for tenant found", status_code=400, payload=None): + super().__init__(message, status_code, payload) + + diff --git a/eveai_app/templates/entitlements/license.html b/eveai_app/templates/entitlements/license.html index 9cb96a1..46d50de 100644 --- a/eveai_app/templates/entitlements/license.html +++ b/eveai_app/templates/entitlements/license.html @@ -11,7 +11,7 @@ {{ form.hidden_tag() }} {% set main_fields = ['start_date', 'end_date', 'currency', 'yearly_payment', 'basic_fee'] %} {% for field in form %} - {{ render_included_field(field, disabled_fields=['currency'], include_fields=main_fields) }} + {{ render_included_field(field, disabled_fields=ext_disabled_fields + ['currency'], include_fields=main_fields) }} {% endfor %}