feat(chat): implement adaptive timeout and enhanced search functionality
- Introduced adaptive timeout logic for web searches and chat streaming, improving responsiveness and efficiency. - Updated `smartSearchRag` method to support timeout adjustments based on search rounds. - Enhanced `executeProgressiveSearch` to utilize adaptive timeouts and improve search result handling. - Added new utility functions for calculating adaptive timeouts based on rounds and attempts. - Integrated event listeners for chat session management, improving user experience during chat interactions. - Refactored chat message handling to accommodate new streaming and timeout features.
This commit is contained in:
1 parent
f2e8a1b933
commit
8c546f6474
13 files changed
+1547
-271
No files matched your search
@@ -127,5 +127,43 @@ export function withTimeout<T>(
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcula timeout adaptativo baseado no round
|
||||
* Reduz 20% a cada round: 10s → 8s → 6s → 4.8s
|
||||
*/
|
||||
export function calculateAdaptiveTimeout(
|
||||
round: number,
|
||||
initialTimeout: number = 10000,
|
||||
reductionRate: number = 0.2
|
||||
): number {
|
||||
const timeout = initialTimeout * Math.pow(1 - reductionRate, round - 1);
|
||||
return Math.max(timeout, 5000); // Mínimo de 5s
|
||||
}
|
||||
|
||||
/**
|
||||
* Calcula timeout por motor baseado em tentativas
|
||||
* Reduz após cada falha: 10s → 7s → 5s
|
||||
*/
|
||||
export function calculateEngineTimeout(
|
||||
attempt: number,
|
||||
initialTimeout: number = 10000,
|
||||
reductionRate: number = 0.3
|
||||
): number {
|
||||
const timeout = initialTimeout * Math.pow(1 - reductionRate, attempt - 1);
|
||||
return Math.max(timeout, 3000); // Mínimo de 3s
|
||||
}
|
||||
|
||||
/**
|
||||
* Configurações otimizadas de timeout
|
||||
*/
|
||||
export const TIMEOUT_CONFIG = {
|
||||
initialTimeout: 10000, // 10s (reduzido de 15s)
|
||||
timeoutReductionPerRound: 0.2, // 20%
|
||||
maxTimeoutPerQuery: 25000, // 25s total por query
|
||||
maxTimeoutPerRound: 15000, // 15s por round
|
||||
minTimeout: 5000, // Mínimo absoluto
|
||||
minEngineTimeout: 3000, // Mínimo por motor
|
||||
} as const;
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user