AI Settings - Sistema Dinamico Completo
AI Settings - Sistema Dinamico Completo
Data: 22 Ottobre 2025 Feature: Gestione AI Provider, Budget, Alert e Monitoring
---
π― Overview Sistema
Nuovo Sottomenu: Impostazioni AI
``
π§ AI Knowledge Base
βββ Dashboard KB
βββ Ambiti
βββ Template
βββ Pattern Library
βββ Playground
βββ Analytics KB
βββ βοΈ Impostazioni AI β NUOVO GRUPPO
βββ π Dashboard Costi
βββ π€ Provider AI
βββ π° Budget & Limiti
βββ π Alert & Notifiche
βββ π΅ Pricing Models
βββ β‘ Performance
βββ π Logs & Debug</p><p>---</p><p><h2>π€ 1. PROVIDER AI (Multi-Provider Support)</h2></p><p><h3><strong>FunzionalitΓ </strong></h3></p><p>β <strong>3 Provider Supportati</strong>: <ul><li><strong>OpenAI</strong> (GPT-4o, GPT-4o-mini, GPT-4-turbo)</li> <li><strong>Anthropic</strong> (Claude 3.5 Sonnet, Claude 3 Haiku)</li> <li><strong>Google</strong> (Gemini 1.5 Flash, Gemini 1.5 Pro)</li></p><p>β <strong>Switch Dinamico</strong>: Cambia provider senza modificare codice</p><p>β <strong>Test Connessione</strong>: Verifica API key prima di salvare</p><p>β <strong>Configurazione Avanzata</strong>: <li>Max tokens per risposta</li> <li>Temperature (creativitΓ )</li> <li>Timeout</li> <li>Retry logic</li></p><p>---</p><p><h3><strong>UI Provider</strong></h3></p><p><strong>3 Card</strong> (una per provider):</p><p>
ββββββββββββββββββββββββββββββββββββββ β π’ OpenAI [Attivo β ] β ββββββββββββββββββββββββββββββββββββββ€ β Modelli Disponibili: β β β’ GPT-4o Mini [Consigliato] β β In: $0.15/1M | Out: $0.60/1M β β β’ GPT-4o β β In: $2.50/1M | Out: $10.00/1M β β β’ GPT-4 Turbo β β In: $10/1M | Out: $30/1M β β β β [Configura OpenAI] β ββββββββββββββββββββββββββββββββββββββ
</p><p><strong>Modal Configurazione</strong>: </code>`<code> βββββββββββββββββββββββββββββββββββββββ β Configura OpenAI β βββββββββββββββββββββββββββββββββββββββ€ β β β API Key: [sk-proj-...] [ποΈ] β β Link: platform.openai.com/api-keys β β β β Modello: [gpt-4o-mini βΌ] β β Pricing: $0.15/1M in | $0.60/1M outβ β β β Max Tokens: [800_______] β β Temperature: [0.3βββββββββ] 0.3 β β Preciso ββ Creativo β β β β [β‘ Test Connessione] β β β Connessione riuscita! β β Modello: gpt-4o-mini | Tokens: 8 β β β β [Annulla] [πΎ Salva Configurazione]β βββββββββββββββββββββββββββββββββββββββ
---
Features Avanzate (Suggerite)
A. Fallback Provider
`
Provider Primario: OpenAI (gpt-4o-mini)
β (se error)
Provider Fallback: Google (gemini-1.5-flash)
β (se error)
Errore all'utente
`Configurazione:
`
βοΈ Abilita fallback automatico
Primario: [OpenAI βΌ]
Fallback: [Google Gemini βΌ]
`---
B. Cost Optimization Auto
`
Se costo mensile > $10
β
Suggerimento: "Passa da GPT-4o a GPT-4o-mini"
Risparmio: -80% ($2/mese invece di $10)
`---
C. Multi-Model Strategy
`
Query semplici (produzione/confronti):
β GPT-4o-mini ($0.15/1M input)Query complesse (ottimizzazione/diagnostica):
β GPT-4o ($2.50/1M input)
`UI Configurazione:
`
Strategia Modelli:
β Single Model (usa sempre stesso)
β Dual Model (semplici vs complessi)
β Cost-Optimized (sceglie piΓΉ economico)
`---
π° 2. BUDGET & LIMITI (Sistema Alert Dinamico)
3 Livelli Budget
Giornaliero π
:
Limite: $1.00/giorno
Alert: 80% ($0.80)
Hard limit: Blocca a 100% Mensile π:
Limite: $25.00/mese
Alert: 80% ($20)
Proiezione automatica Annuale π:
Limite: $250.00/anno
Alert: 80% ($200)
Trend YoY ---
Dashboard Real-Time
3 Card con Progress Bar (aggiornamento ogni 30s):
`ββββββββββββββββββββββββββββββββββββ β π Budget Giornaliero β ββββββββββββββββββββββββββββββββββββ€ β Limite: $1.00 β β Utilizzato: $0.15 β β β β [ββββββββββ] 15% β β β β Rimanente: $0.85 β ββββββββββββββββββββββββββββββββββββ
</p><p><strong>Colori dinamici</strong>: <li>Verde: 0-50%</li> <li>Giallo: 50-80%</li> <li>Arancione: 80-100%</li> <li>Rosso: >100% (sforato)</li></p><p>---</p><p><h3><strong>Alert Automatici</strong></h3></p><p><strong>Quando scatta</strong>: <li>Budget raggiunge 80% (configurabile)</li> <li>Costo giornaliero anomalo (>2Γ media)</li> <li>Hard limit 100% (blocco AI)</li></p><p><strong>Canali notifica</strong>: <li>βοΈ Email (lista configurabile)</li> <li>βοΈ Slack (webhook)</li> <li>βοΈ In-App (notification bell)</li></p><p><strong>Email Template</strong>:
Oggetto: β οΈ AI Budget Alert - Soglia RaggiuntaCiao Admin,
Il budget AI ha raggiunto l'80% del limite giornaliero:
Budget: $1.00
Utilizzato: $0.82 (82%)
Rimanente: $0.18
Causa: 1.200 query oggi (vs media 800)
Ambito costoso: Diagnostica ($0.35)
Raccomandazioni:
β’ Crea piΓΉ template per ambito Diagnostica
β’ Verifica query anomale
[Visualizza Dashboard Costi]
---
AI Assistant - sartUP
`</p><p>---</p><p><h3><strong>Hard Limit (Blocco Automatico)</strong></h3></p><p>Se attivato e budget raggiunge 100%:</p><p></code>`<code> ββββββββββββββββββββββββββββββββββββββ β β HARD LIMIT RAGGIUNTO β ββββββββββββββββββββββββββββββββββββββ€ β Budget giornaliero esaurito! β β β β Le chiamate AI sono state β β bloccate automaticamente. β β β β [Aumenta Budget] β β [Disabilita Blocco] β ββββββββββββββββββββββββββββββββββββββ
Utenti vedono:
`
β AI Assistant temporaneamente non disponibile.
Riprova domani o contatta l'amministratore.
`---
π 3. ALERT & NOTIFICHE
Tipi Alert
Budget Alert:
Soglia raggiunta (80%, 90%, 100%)
Sconfinamento
Proiezione mensile oltre budget Performance Alert:
Latency > 5s
Error rate > 5%
Template coverage < 70% Anomaly Alert:
Picco query inaspettato (+200% vs media)
Costo anomalo (singola query >$0.01)
Provider down ---
Dashboard Alert
`ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β π Alert Attivi β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β β β β οΈ Budget mensile: 85% (Alert: 80%) β β 22/10/2025 10:30 | Inviato a: admin@sartup.it β β [Visualizza] [Disattiva] β β β β π΄ Budget giornaliero: 105% (Sforato) β β 22/10/2025 14:15 | Hard limit attivato β β [Aumenta Budget] [Disabilita Hard Limit] β β β β π‘ Performance: Latency media 6.2s (>5s) β β 22/10/2025 09:00 | OpenAI lento β β [Dettagli] [Ignora] β β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
---
π΅ 4. PRICING MODELS (Gestione Dinamica Prezzi)
FunzionalitΓ
Invece di hardcodare prezzi nel codice, li gestisci via UI:
`ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β Modelli Configurati β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β β β gpt-4o-mini (OpenAI) [Attivo]β β Input: $0.15/1M tokens β β Output: $0.60/1M tokens β β Costo medio query: $0.0001 β β [βοΈ Modifica] [ποΈ] β β β β claude-3-haiku (Anthropic) [Inattivo]β β Input: $0.25/1M tokens β β Output: $1.25/1M tokens β β [βοΈ] [ποΈ] β β β β [β Aggiungi Nuovo Modello] β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
</p><p><strong>Vantaggi</strong>: <li>β Aggiorna prezzi quando OpenAI cambia tariffe</li> <li>β Aggiungi nuovi modelli senza deploy</li> <li>β Confronta costi tra provider</li> <li>β Calcoli automatici sempre corretti</li></p><p>---</p><p><h2>β‘ 5. PERFORMANCE MONITORING</h2></p><p><h3><strong>Metriche Monitorate</strong></h3></p><p><strong>Latency</strong>: <li>Tempo medio risposta AI</li> <li>P95, P99 (percentili)</li> <li>Breakdown per provider</li></p><p><strong>Success Rate</strong>: <li>% chiamate riuscite</li> <li>Errori per tipo</li> <li>Retry necessari</li></p><p><strong>Throughput</strong>: <li>Query/secondo</li> <li>Picchi orari</li> <li>Capacity planning</li></p><p>---</p><p><h3><strong>Dashboard Performance</strong></h3></p><p>
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β‘ Performance Metrics (Ultimi 7 giorni) β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β β β Latency Media: 1.2s β β β P95: 2.8s | P99: 4.5s β β [Grafico latency 7 giorni] β β β β Success Rate: 98.5% β β β Errori: 15/1000 (1.5%) β β [Breakdown errori] β β β β Throughput Peak: 45 query/min β β Orario picco: 10:00-11:00 β β [Grafico distribuzione oraria] β β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
</p><p>---</p><p><h2>π 6. LOGS & DEBUG</h2></p><p><h3><strong>Log Chiamate AI</strong></h3></p><p>Tabella con tutte le chiamate API (ultimi 1000):</p><p>| Timestamp | Provider | Model | Endpoint | Tokens | Latency | Status | Error | |-----------|----------|-------|----------|--------|---------|--------|-------| | 10:30:15 | OpenAI | gpt-4o-mini | chat | 450 | 1.2s | β | - | | 10:32:18 | OpenAI | gpt-4o-mini | chat | 520 | 2.1s | β | - | | 10:35:22 | OpenAI | gpt-4o-mini | chat | 0 | 5.8s | β | Rate limit | | 10:35:25 | Google | gemini-flash | chat | 480 | 0.9s | β | Fallback |</p><p>---</p><p><h3><strong>Filtri Log</strong></h3></p><p>
[Provider: Tutti βΌ] [Status: Tutti βΌ] [Da: 22/10 | A: 22/10]Ricerca: [Rate limit____________] [π]
`</p><p>---</p><p><h3><strong>Debug Mode</strong></h3></p><p></code>`<code> βοΈ Abilita debug mode</p><p>Quando attivo: β’ Logga tutte le chiamate (anche cache hit) β’ Salva prompt completi (per analisi) β’ Mostra stack trace errori β’ Export log JSON</p><p>β οΈ Disattivare in produzione (performance impact)
</p><p>---</p><p><h2>π‘ SUGGERIMENTI IMPLEMENTATIVI</h2></p><p><h3><strong>Suggerimento 1: Middleware Budget Check</strong></h3></p><p><strong>Blocca chiamate AI</strong> se hard limit raggiunto:</p><p></code>`<code>php
// app/Http/Middleware/CheckAiBudget.php</p><p>public function handle($request, Closure $next)
{
$budgetService = app(AiBudgetService::class);
if ($budgetService->isHardLimitReached()) {
return response()->json([
'error' => 'Budget AI esaurito. Riprova domani.',
'hard_limit' => true,
], 429); // Too Many Requests
}
return $next($request);
}
</code>`<code></p><p>---</p><p><h3><strong>Suggerimento 2: Cost Optimizer Service</strong></h3></p><p><strong>Analizza usage</strong> e suggerisce automaticamente:</p><p></code>`<code>php
public function suggestOptimizations(): array
{
$suggestions = [];
// 1. Switch modello piΓΉ economico
if ($this->avgCostPerQuery > 0.0002) {
$suggestions[] = [
'type' => 'model_downgrade',
'current' => 'gpt-4o',
'suggested' => 'gpt-4o-mini',
'savings' => '$8/mese (-80%)',
];
}
// 2. Aumenta template coverage
$coverage = $this->getTemplateCoverage();
if ($coverage < 80) {
$topLlmQueries = $this->getTopLlmQueries(10);
$suggestions[] = [
'type' => 'create_templates',
'queries' => $topLlmQueries,
'savings' => '$2/mese (-25%)',
];
}
// 3. Ottimizza cache
if ($this->cacheHitRate < 40) {
$suggestions[] = [
'type' => 'increase_cache_ttl',
'current' => '1h',
'suggested' => '3h',
'savings' => '$0.50/mese (-6%)',
];
}
return $suggestions;
}
</code>`<code></p><p><strong>UI Suggestions</strong>:
</code>`<code>
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π‘ Raccomandazioni Ottimizzazione β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. Passa a GPT-4o-mini β
β Risparmio: $8/mese (-80%) β
β Impact: Minimo (qualitΓ simile) β
β [Applica Automaticamente] β
β β
β 2. Crea 5 template per Diagnostica β
β Risparmio: $2/mese (-25%) β
β Template suggeriti: β
β β’ "PerchΓ© produzione bassa?" (35 query/mese) β
β β’ "Errori di oggi" (28 query/mese) β
β [Genera Template con AI] β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ</p><p>---</p><p><h3><strong>Suggerimento 3: Budget Presets</strong></h3></p><p><strong>Template budget pronti</strong>:</p><p></code>`<code> Preset Budget:</p><p>β Startup (Test) β’ Giornaliero: $0.50 β’ Mensile: $10 β’ Annuale: $100 β Standard (50 utenti) β’ Giornaliero: $1.00 β’ Mensile: $25 β’ Annuale: $250 β Enterprise (200+ utenti) β’ Giornaliero: $5.00 β’ Mensile: $100 β’ Annuale: $1.000</p><p>[Applica Preset]
</p><p>---</p><p><h3><strong>Suggerimento 4: Budget Sharing per Ambito</strong></h3></p><p><strong>Suddividi budget</strong> tra ambiti:</p><p></code>`<code> Budget Mensile: $25</p><p>Allocazione per Ambito: π Produzione: $10 (40%) [βββββββββββββ] π§ Diagnostica: $8 (32%) [βββββββββββββ] π₯ Operatori: $4 (16%) [βββββββββββββ] π Pianificazione: $3 (12%) [βββββββββββββ]</p><p>[Auto-Allocazione] [Manuale]
Alert per ambito:
`
β οΈ Ambito "Diagnostica" ha raggiunto $6.50/$8 (81%)
Considera creare piΓΉ template o ridurre allocazione.
`---
π 7. DASHBOARD COSTI (Riorganizzata)
Nuova Posizione
Prima: Standalone sotto AI KB
Ora: Prima voce in "Impostazioni AI"
Motivo: Logicamente fa parte delle impostazioni
---
Features Aggiunte
1. Filtri Avanzati
`[Ambito: Tutti βΌ] [Tipo: Tutti βΌ] [Periodo: Questo mese βΌ]</p><p>Tipo Utilizzo: βοΈ KB Generation (generazione template) βοΈ User Queries (query utenti) βοΈ Intent Detection (rilevamento intent) βοΈ Debug/Test (chiamate test)
</p><p>---</p><p><h4><strong>2. Comparison View</strong></h4></p><p></code>`<code> Confronta Periodi:</p><p>[Questo mese] vs [Scorso mese]</p><p>β Metrica β Questo mese β Scorso mese β Delta β β Costo totale β $2.50 β $4.20 β -40% πβ β Query totali β 1.200 β 950 β +26% πβ β Template coverageβ 82% β 65% β +17% β β β Costo/query β $0.002 β $0.004 β -50% πβ
---
3. Forecast
`
π Previsioni Fine MeseBasato su 22 giorni:
β’ Utilizzo attuale: $2.50
β’ Giorni rimanenti: 8
β’ Proiezione: $3.20
Status: β
Sotto budget ($25)
Margine: $21.80 (87% rimanente)
`---
π― FEATURES DINAMICHE SUGGERITE
A. Auto-Scaling Budget
Sistema adatta budget automaticamente:
`
Se utilizzo < 50% per 3 mesi:
β Suggerisci riduzione budget (-20%)Se utilizzo > 90% per 2 mesi:
β Suggerisci aumento budget (+30%)
`</p><p>---</p><p><h3><strong>B. Cost Allocation</strong></h3></p><p><strong>Addebita costi</strong> per centro di costo:</p><p></code>`<code> Reparto Produzione: β’ Query: 450 β’ Costo: $0.80 (32% totale)</p><p>Reparto QualitΓ : β’ Query: 120 β’ Costo: $0.25 (10% totale)</p><p>[Export per ContabilitΓ ]
---
C. Budget Pooling
Condivisione budget tra servizi:
`
Budget Totale AI: $50/meseServizi:
β’ AI Assistant i40: $25 (50%)
β’ AI Document Analysis: $15 (30%)
β’ AI Image Recognition: $10 (20%)
[Configura Pooling]
`</p><p>---</p><p><h3><strong>D. Prepaid Credits</strong></h3></p><p><strong>Sistema prepagato</strong>:</p><p></code>`<code> Crediti Disponibili: $100</p><p>Acquista Pacchetti: β $50 (Bonus +5%) β $52.50 crediti β $100 (Bonus +10%) β $110 crediti β $500 (Bonus +20%) β $600 crediti</p><p>[Acquista Credits]
---
π IMPLEMENTAZIONE
File Creati
Controllers:
β
AiProviderController.php (gestione provider)
β
AiBudgetController.php (gestione budget)
β
AiCostTrackingController.php (giΓ fatto)Views:
β
provider/index.blade.php (UI multi-provider)
β
budget/index.blade.php (UI budget real-time)
β
cost-tracking/index.blade.php (giΓ fatto)Migrations:
β
2025_10_22_000002_create_ai_settings_tables.phpRoute:
β
/admin/ai/settings/* (7 endpoint)Menu SQL:
β
ai_settings_menu_structure.sql
β
ai_settings_tables.sql---
Script SQL da Eseguire
1. Menu:
/Users/nscapati/Desktop/ai_settings_menu_structure.sql
2. Tables: /Users/nscapati/Desktop/ai_settings_tables.sql---
Route Disponibili
`
admin.ai.settings.cost-tracking β Dashboard costi
admin.ai.settings.provider β Gestione provider
admin.ai.settings.budget β Budget & limiti
admin.ai.settings.alerts β Alert (placeholder)
admin.ai.settings.pricing β Pricing models (placeholder)
admin.ai.settings.performance β Performance (placeholder)
admin.ai.settings.logs β Logs debug (placeholder)
`</p><p>---</p><p><h2>β STATO ATTUALE</h2></p><p><h3><strong>Implementato</strong> (Pronto)</h3> <li>β Menu strutturato (7 voci)</li> <li>β Provider AI (multi-provider support)</li> <li>β Budget & Limiti (real-time tracking)</li> <li>β Dashboard Costi (dettagliato)</li> <li>β Database tables (settings + alerts + logs)</li> <li>β Route complete</li></p><p><h3><strong>Placeholder</strong> (Da Sviluppare)</h3> <li>β οΈ Alert & Notifiche (UI alert center)</li> <li>β οΈ Pricing Models (gestione prezzi dinamici)</li> <li>β οΈ Performance (monitoring latency)</li> <li>β οΈ Logs & Debug (viewer log)</li></p><p>---</p><p><h2>π― PROSSIMI STEP</h2></p><p><h3><strong>Ora</strong></h3> 1. Esegui script SQL (menu + tables) 2. Testa
3. Testa /admin/ai/settings/budget
4. Testa /admin/ai/settings/cost-trackingPost-Meeting Venerdì
1. Configura OpenAI API key (Provider)
2. Imposta budget iniziale
3. Attiva alert
4. Inizia uso AI Generator
5. Monitora costi real-time---
π° Budget Consigliato (Setup Iniziale)
Fase Test (Prima settimana)
`
Giornaliero: $0.50
Mensile: $10
Annuale: $100Alert: 80%
Hard limit: No (per non bloccare test)
`Fase Produzione (Dopo 1 mese)
`
Giornaliero: $0.20 (adeguato a uso reale)
Mensile: $5
Annuale: $50Alert: 80%
Hard limit: Sì
``---
β SISTEMA COMPLETO!
Hai ora:
Interfacciamento AI estremamente dinamico come richiesto! π
---
Vuoi che aggiungo altre features o va bene cosΓ¬? πͺ
Analisi Codice
Blocco 1
π§ AI Knowledge Base
βββ Dashboard KB
βββ Ambiti
βββ Template
βββ Pattern Library
βββ Playground
βββ Analytics KB
βββ βοΈ Impostazioni AI β NUOVO GRUPPO
βββ π Dashboard Costi
βββ π€ Provider AI
βββ π° Budget & Limiti
βββ π Alert & Notifiche
βββ π΅ Pricing Models
βββ β‘ Performance
βββ π Logs & Debug
Blocco 2
ββββββββββββββββββββββββββββββββββββββ
β π’ OpenAI [Attivo β
] β
ββββββββββββββββββββββββββββββββββββββ€
β Modelli Disponibili: β
β β’ GPT-4o Mini [Consigliato] β
β In: $0.15/1M | Out: $0.60/1M β
β β’ GPT-4o β
β In: $2.50/1M | Out: $10.00/1M β
β β’ GPT-4 Turbo β
β In: $10/1M | Out: $30/1M β
β β
β [Configura OpenAI] β
ββββββββββββββββββββββββββββββββββββββ
Blocco 3
βββββββββββββββββββββββββββββββββββββββ
β Configura OpenAI β
βββββββββββββββββββββββββββββββββββββββ€
β β
β API Key: [sk-proj-...] [ποΈ] β
β Link: platform.openai.com/api-keys β
β β
β Modello: [gpt-4o-mini βΌ] β
β Pricing: $0.15/1M in | $0.60/1M outβ
β β
β Max Tokens: [800_______] β
β Temperature: [0.3βββββββββ] 0.3 β
β Preciso ββ Creativo β
β β
β [β‘ Test Connessione] β
β β
Connessione riuscita! β
β Modello: gpt-4o-mini | Tokens: 8 β
β β
β [Annulla] [πΎ Salva Configurazione]β
βββββββββββββββββββββββββββββββββββββββ
Blocco 4
Provider Primario: OpenAI (gpt-4o-mini)
β (se error)
Provider Fallback: Google (gemini-1.5-flash)
β (se error)
Errore all'utente
Blocco 5
βοΈ Abilita fallback automatico
Primario: [OpenAI βΌ]
Fallback: [Google Gemini βΌ]
Blocco 6
Se costo mensile > $10
β
Suggerimento: "Passa da GPT-4o a GPT-4o-mini"
Risparmio: -80% ($2/mese invece di $10)
Blocco 7
Query semplici (produzione/confronti):
β GPT-4o-mini ($0.15/1M input)
Query complesse (ottimizzazione/diagnostica):
β GPT-4o ($2.50/1M input)
Blocco 8
Strategia Modelli:
β Single Model (usa sempre stesso)
β Dual Model (semplici vs complessi)
β Cost-Optimized (sceglie piΓΉ economico)
Blocco 9
ββββββββββββββββββββββββββββββββββββ
β π
Budget Giornaliero β
ββββββββββββββββββββββββββββββββββββ€
β Limite: $1.00 β
β Utilizzato: $0.15 β
β β
β [ββββββββββ] 15% β
β β
β Rimanente: $0.85 β
ββββββββββββββββββββββββββββββββββββ
Blocco 10
Oggetto: β οΈ AI Budget Alert - Soglia Raggiunta
Ciao Admin,
Il budget AI ha raggiunto l'80% del limite giornaliero:
Budget: $1.00
Utilizzato: $0.82 (82%)
Rimanente: $0.18
Causa: 1.200 query oggi (vs media 800)
Ambito costoso: Diagnostica ($0.35)
Raccomandazioni:
β’ Crea piΓΉ template per ambito Diagnostica
β’ Verifica query anomale
[Visualizza Dashboard Costi]
---
AI Assistant - sartUP
Blocco 11
ββββββββββββββββββββββββββββββββββββββ
β β HARD LIMIT RAGGIUNTO β
ββββββββββββββββββββββββββββββββββββββ€
β Budget giornaliero esaurito! β
β β
β Le chiamate AI sono state β
β bloccate automaticamente. β
β β
β [Aumenta Budget] β
β [Disabilita Blocco] β
ββββββββββββββββββββββββββββββββββββββ
Blocco 12
β AI Assistant temporaneamente non disponibile.
Riprova domani o contatta l'amministratore.
Blocco 13
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Alert Attivi β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β β οΈ Budget mensile: 85% (Alert: 80%) β
β 22/10/2025 10:30 | Inviato a: admin@sartup.it β
β [Visualizza] [Disattiva] β
β β
β π΄ Budget giornaliero: 105% (Sforato) β
β 22/10/2025 14:15 | Hard limit attivato β
β [Aumenta Budget] [Disabilita Hard Limit] β
β β
β π‘ Performance: Latency media 6.2s (>5s) β
β 22/10/2025 09:00 | OpenAI lento β
β [Dettagli] [Ignora] β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Blocco 14
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Modelli Configurati β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β gpt-4o-mini (OpenAI) [Attivo]β
β Input: $0.15/1M tokens β
β Output: $0.60/1M tokens β
β Costo medio query: $0.0001 β
β [βοΈ Modifica] [ποΈ] β
β β
β claude-3-haiku (Anthropic) [Inattivo]β
β Input: $0.25/1M tokens β
β Output: $1.25/1M tokens β
β [βοΈ] [ποΈ] β
β β
β [β Aggiungi Nuovo Modello] β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Blocco 15
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β‘ Performance Metrics (Ultimi 7 giorni) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Latency Media: 1.2s β
β
β P95: 2.8s | P99: 4.5s β
β [Grafico latency 7 giorni] β
β β
β Success Rate: 98.5% β
β
β Errori: 15/1000 (1.5%) β
β [Breakdown errori] β
β β
β Throughput Peak: 45 query/min β
β Orario picco: 10:00-11:00 β
β [Grafico distribuzione oraria] β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Blocco 16
[Provider: Tutti βΌ] [Status: Tutti βΌ] [Da: 22/10 | A: 22/10]
Ricerca: [Rate limit____________] [π]
Blocco 17
βοΈ Abilita debug mode
Quando attivo:
β’ Logga tutte le chiamate (anche cache hit)
β’ Salva prompt completi (per analisi)
β’ Mostra stack trace errori
β’ Export log JSON
β οΈ Disattivare in produzione (performance impact)
Blocco 18 php
// app/Http/Middleware/CheckAiBudget.php
public function handle($request, Closure $next)
{
$budgetService = app(AiBudgetService::class);
if ($budgetService->isHardLimitReached()) {
return response()->json([
'error' => 'Budget AI esaurito. Riprova domani.',
'hard_limit' => true,
], 429); // Too Many Requests
}
return $next($request);
}
Blocco 19 php
public function suggestOptimizations(): array
{
$suggestions = [];
// 1. Switch modello piΓΉ economico
if ($this->avgCostPerQuery > 0.0002) {
$suggestions[] = [
'type' => 'model_downgrade',
'current' => 'gpt-4o',
'suggested' => 'gpt-4o-mini',
'savings' => '$8/mese (-80%)',
];
}
// 2. Aumenta template coverage
$coverage = $this->getTemplateCoverage();
if ($coverage < 80) {
$topLlmQueries = $this->getTopLlmQueries(10);
$suggestions[] = [
'type' => 'create_templates',
'queries' => $topLlmQueries,
'savings' => '$2/mese (-25%)',
];
}
// 3. Ottimizza cache
if ($this->cacheHitRate < 40) {
$suggestions[] = [
'type' => 'increase_cache_ttl',
'current' => '1h',
'suggested' => '3h',
'savings' => '$0.50/mese (-6%)',
];
}
return $suggestions;
}
Blocco 20
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π‘ Raccomandazioni Ottimizzazione β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β 1. Passa a GPT-4o-mini β
β Risparmio: $8/mese (-80%) β
β Impact: Minimo (qualitΓ simile) β
β [Applica Automaticamente] β
β β
β 2. Crea 5 template per Diagnostica β
β Risparmio: $2/mese (-25%) β
β Template suggeriti: β
β β’ "PerchΓ© produzione bassa?" (35 query/mese) β
β β’ "Errori di oggi" (28 query/mese) β
β [Genera Template con AI] β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Blocco 21
Preset Budget:
β Startup (Test)
β’ Giornaliero: $0.50
β’ Mensile: $10
β’ Annuale: $100
β Standard (50 utenti)
β’ Giornaliero: $1.00
β’ Mensile: $25
β’ Annuale: $250
β Enterprise (200+ utenti)
β’ Giornaliero: $5.00
β’ Mensile: $100
β’ Annuale: $1.000
[Applica Preset]
Blocco 22
Budget Mensile: $25
Allocazione per Ambito:
π Produzione: $10 (40%) [βββββββββββββ]
π§ Diagnostica: $8 (32%) [βββββββββββββ]
π₯ Operatori: $4 (16%) [βββββββββββββ]
π
Pianificazione: $3 (12%) [βββββββββββββ]
[Auto-Allocazione] [Manuale]
Blocco 23
β οΈ Ambito "Diagnostica" ha raggiunto $6.50/$8 (81%)
Considera creare piΓΉ template o ridurre allocazione.
Blocco 24
[Ambito: Tutti βΌ] [Tipo: Tutti βΌ] [Periodo: Questo mese βΌ]
Tipo Utilizzo:
βοΈ KB Generation (generazione template)
βοΈ User Queries (query utenti)
βοΈ Intent Detection (rilevamento intent)
βοΈ Debug/Test (chiamate test)
Blocco 25
Confronta Periodi:
[Questo mese] vs [Scorso mese]
β Metrica β Questo mese β Scorso mese β Delta β
β Costo totale β $2.50 β $4.20 β -40% πβ
β Query totali β 1.200 β 950 β +26% πβ
β Template coverageβ 82% β 65% β +17% β
β
β Costo/query β $0.002 β $0.004 β -50% πβ
Blocco 26
π Previsioni Fine Mese
Basato su 22 giorni:
β’ Utilizzo attuale: $2.50
β’ Giorni rimanenti: 8
β’ Proiezione: $3.20
Status: β
Sotto budget ($25)
Margine: $21.80 (87% rimanente)
Blocco 27
Se utilizzo < 50% per 3 mesi:
β Suggerisci riduzione budget (-20%)
Se utilizzo > 90% per 2 mesi:
β Suggerisci aumento budget (+30%)
Blocco 28
Reparto Produzione:
β’ Query: 450
β’ Costo: $0.80 (32% totale)
Reparto QualitΓ :
β’ Query: 120
β’ Costo: $0.25 (10% totale)
[Export per ContabilitΓ ]
Blocco 29
Budget Totale AI: $50/mese
Servizi:
β’ AI Assistant i40: $25 (50%)
β’ AI Document Analysis: $15 (30%)
β’ AI Image Recognition: $10 (20%)
[Configura Pooling]
Blocco 30
Crediti Disponibili: $100
Acquista Pacchetti:
β $50 (Bonus +5%) β $52.50 crediti
β $100 (Bonus +10%) β $110 crediti
β $500 (Bonus +20%) β $600 crediti
[Acquista Credits]
Blocco 31
admin.ai.settings.cost-tracking β Dashboard costi
admin.ai.settings.provider β Gestione provider
admin.ai.settings.budget β Budget & limiti
admin.ai.settings.alerts β Alert (placeholder)
admin.ai.settings.pricing β Pricing models (placeholder)
admin.ai.settings.performance β Performance (placeholder)
admin.ai.settings.logs β Logs debug (placeholder)
Blocco 32
Giornaliero: $0.50
Mensile: $10
Annuale: $100
Alert: 80%
Hard limit: No (per non bloccare test)
Blocco 33
Giornaliero: $0.20 (adeguato a uso reale)
Mensile: $5
Annuale: $50
Alert: 80%
Hard limit: Sì