feat: add cost/token tracking, monthly budget system, and dry-run mode
- Create PSA_Cost_Tracker class with database table for API call logging - Log prompt/completion tokens and estimated cost for every OpenRouter API call - Implement monthly budget system with hard stop (budget of 0 = unlimited) - Add budget checks in validate_peptide_name() and generate_peptide_content() - Add dry_run() method to estimate costs before making API calls - Display monthly usage summary and recent API logs in admin settings - Add monthly_budget setting to admin interface with number input field - Update uninstall.php to drop psa_api_logs table on plugin removal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
44
includes/class-psa-config.php
Executable file
44
includes/class-psa-config.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Configuration constants for Peptide Search AI.
|
||||
* Centralizes all magic numbers and configuration values.
|
||||
*
|
||||
* @package PeptideSearchAI
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class PSA_Config {
|
||||
|
||||
// Search query validation
|
||||
const MIN_QUERY_LENGTH = 2;
|
||||
const MAX_QUERY_LENGTH = 100;
|
||||
|
||||
// Rate limiting (requests per hour)
|
||||
const REST_RATE_LIMIT = 20;
|
||||
const AJAX_RATE_LIMIT = 10;
|
||||
|
||||
// Daily generation cap
|
||||
const DAILY_GENERATION_CAP = 50;
|
||||
|
||||
// Generation timing
|
||||
const PENDING_TIMEOUT = 300; // seconds (5 minutes)
|
||||
const MAX_GENERATION_RETRIES = 3;
|
||||
|
||||
// AI token limits
|
||||
const VALIDATION_MAX_TOKENS = 300;
|
||||
const GENERATION_MAX_TOKENS = 4096;
|
||||
|
||||
// Cache TTL
|
||||
const VALIDATION_CACHE_TTL = null; // Set to DAY_IN_SECONDS at runtime
|
||||
const PUBCHEM_CACHE_TTL = null; // Set to 7 * DAY_IN_SECONDS at runtime
|
||||
|
||||
// API retry settings
|
||||
const API_RETRY_MAX = 3;
|
||||
const API_RETRY_BASE_DELAY = 5; // seconds
|
||||
|
||||
// Cost tracking and budget
|
||||
const DEFAULT_MONTHLY_BUDGET = 0; // 0 = unlimited
|
||||
}
|
||||
Reference in New Issue
Block a user