- Created a new eveai_chat plugin to support the new dynamic possibilities of the Specialists. Currently only supports standard Rag retrievers (i.e. no extra arguments).
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace EveAI\Chat;
|
||||
|
||||
class RateLimiter {
|
||||
private const RATE_LIMIT_KEY = 'eveai_rate_limit_';
|
||||
private const MAX_REQUESTS = 60; // Maximum requests per window
|
||||
private const WINDOW_SECONDS = 60; // Time window in seconds
|
||||
|
||||
public static function check_rate_limit($identifier): bool {
|
||||
$key = self::RATE_LIMIT_KEY . $identifier;
|
||||
$requests = get_transient($key);
|
||||
|
||||
if ($requests === false) {
|
||||
set_transient($key, 1, self::WINDOW_SECONDS);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($requests >= self::MAX_REQUESTS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
set_transient($key, $requests + 1, self::WINDOW_SECONDS);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get_remaining_requests($identifier): int {
|
||||
$key = self::RATE_LIMIT_KEY . $identifier;
|
||||
$requests = get_transient($key);
|
||||
|
||||
if ($requests === false) {
|
||||
return self::MAX_REQUESTS;
|
||||
}
|
||||
|
||||
return max(0, self::MAX_REQUESTS - $requests);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user