.
This commit is contained in:
@@ -759,6 +759,15 @@ public class MarketingAnalysisService {
|
|||||||
logger.error("Error in audience analysis: {}", e.getMessage(), e);
|
logger.error("Error in audience analysis: {}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Пауза 15 секунд между вызовами для предотвращения 429 ошибок
|
||||||
|
try {
|
||||||
|
logger.info("Waiting 15 seconds before next analysis block to prevent rate limits");
|
||||||
|
Thread.sleep(15000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
logger.warn("Interrupted during delay between analysis blocks");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Starting competitor analysis generation");
|
logger.info("Starting competitor analysis generation");
|
||||||
Map<String, Object> competitorAnalysis = getCompetitorAnalysis(request);
|
Map<String, Object> competitorAnalysis = getCompetitorAnalysis(request);
|
||||||
@@ -772,6 +781,15 @@ public class MarketingAnalysisService {
|
|||||||
logger.error("Error in competitor analysis: {}", e.getMessage(), e);
|
logger.error("Error in competitor analysis: {}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Пауза 15 секунд между вызовами для предотвращения 429 ошибок
|
||||||
|
try {
|
||||||
|
logger.info("Waiting 15 seconds before next analysis block to prevent rate limits");
|
||||||
|
Thread.sleep(15000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
logger.warn("Interrupted during delay between analysis blocks");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Starting seasonality and market analysis generation");
|
logger.info("Starting seasonality and market analysis generation");
|
||||||
Map<String, Object> seasonalityAndMarket = getSeasonalityAndMarket(request);
|
Map<String, Object> seasonalityAndMarket = getSeasonalityAndMarket(request);
|
||||||
@@ -785,6 +803,15 @@ public class MarketingAnalysisService {
|
|||||||
logger.error("Error in seasonality analysis: {}", e.getMessage(), e);
|
logger.error("Error in seasonality analysis: {}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Пауза 15 секунд между вызовами для предотвращения 429 ошибок
|
||||||
|
try {
|
||||||
|
logger.info("Waiting 15 seconds before next analysis block to prevent rate limits");
|
||||||
|
Thread.sleep(15000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
logger.warn("Interrupted during delay between analysis blocks");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Starting strategy and funnel analysis generation");
|
logger.info("Starting strategy and funnel analysis generation");
|
||||||
Map<String, Object> strategyAndFunnel = getStrategyAndFunnel(request);
|
Map<String, Object> strategyAndFunnel = getStrategyAndFunnel(request);
|
||||||
@@ -954,8 +981,10 @@ public class MarketingAnalysisService {
|
|||||||
String prompt = promptBuilder.toString();
|
String prompt = promptBuilder.toString();
|
||||||
logger.debug("getAudienceAnalysis: Generating audience analysis with detailed prompt (length: {} chars)",
|
logger.debug("getAudienceAnalysis: Generating audience analysis with detailed prompt (length: {} chars)",
|
||||||
prompt.length());
|
prompt.length());
|
||||||
logger.info("getAudienceAnalysis: Calling OpenAI API for audience analysis");
|
logger.info(
|
||||||
String jsonResponse = openAIAnalyticsService.generateWithInstruction(context, prompt, "ru");
|
"getAudienceAnalysis: Calling OpenAI API for audience analysis using miniModelName (gpt-4o-mini)");
|
||||||
|
String jsonResponse = openAIAnalyticsService.generateWithInstructionWithModel(context, prompt, "ru",
|
||||||
|
miniModelName);
|
||||||
logger.debug("getAudienceAnalysis: OpenAI response received. Length: {} chars",
|
logger.debug("getAudienceAnalysis: OpenAI response received. Length: {} chars",
|
||||||
jsonResponse != null ? jsonResponse.length() : 0);
|
jsonResponse != null ? jsonResponse.length() : 0);
|
||||||
|
|
||||||
@@ -1154,8 +1183,10 @@ public class MarketingAnalysisService {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"getCompetitorAnalysis: Generating competitor analysis with detailed prompt (length: {} chars)",
|
"getCompetitorAnalysis: Generating competitor analysis with detailed prompt (length: {} chars)",
|
||||||
prompt.length());
|
prompt.length());
|
||||||
logger.info("getCompetitorAnalysis: Calling OpenAI API for competitor analysis");
|
logger.info(
|
||||||
String jsonResponse = openAIAnalyticsService.generateWithInstruction(context, prompt, "ru");
|
"getCompetitorAnalysis: Calling OpenAI API for competitor analysis using miniModelName (gpt-4o-mini)");
|
||||||
|
String jsonResponse = openAIAnalyticsService.generateWithInstructionWithModel(context, prompt, "ru",
|
||||||
|
miniModelName);
|
||||||
logger.debug("getCompetitorAnalysis: OpenAI response received. Length: {} chars",
|
logger.debug("getCompetitorAnalysis: OpenAI response received. Length: {} chars",
|
||||||
jsonResponse != null ? jsonResponse.length() : 0);
|
jsonResponse != null ? jsonResponse.length() : 0);
|
||||||
|
|
||||||
@@ -1333,9 +1364,10 @@ public class MarketingAnalysisService {
|
|||||||
try {
|
try {
|
||||||
attempt++;
|
attempt++;
|
||||||
logger.info(
|
logger.info(
|
||||||
"getSeasonalityAndMarket: Calling OpenAI API for seasonality and market analysis (attempt {}/{})",
|
"getSeasonalityAndMarket: Calling OpenAI API for seasonality and market analysis (attempt {}/{}) using miniModelName (gpt-4o-mini)",
|
||||||
attempt, MAX_RETRY_ATTEMPTS);
|
attempt, MAX_RETRY_ATTEMPTS);
|
||||||
String jsonResponse = openAIAnalyticsService.generateWithInstruction(context, prompt, "ru");
|
String jsonResponse = openAIAnalyticsService.generateWithInstructionWithModel(context, prompt, "ru",
|
||||||
|
miniModelName);
|
||||||
logger.debug("getSeasonalityAndMarket: OpenAI response received. Length: {} chars",
|
logger.debug("getSeasonalityAndMarket: OpenAI response received. Length: {} chars",
|
||||||
jsonResponse != null ? jsonResponse.length() : 0);
|
jsonResponse != null ? jsonResponse.length() : 0);
|
||||||
|
|
||||||
@@ -1506,9 +1538,10 @@ public class MarketingAnalysisService {
|
|||||||
try {
|
try {
|
||||||
attempt++;
|
attempt++;
|
||||||
logger.info(
|
logger.info(
|
||||||
"getStrategyAndFunnel: Calling OpenAI API for strategy and funnel analysis (attempt {}/{})",
|
"getStrategyAndFunnel: Calling OpenAI API for strategy and funnel analysis (attempt {}/{}) using miniModelName (gpt-4o-mini)",
|
||||||
attempt, MAX_RETRY_ATTEMPTS);
|
attempt, MAX_RETRY_ATTEMPTS);
|
||||||
String jsonResponse = openAIAnalyticsService.generateWithInstruction(context, prompt, "ru");
|
String jsonResponse = openAIAnalyticsService.generateWithInstructionWithModel(context, prompt, "ru",
|
||||||
|
miniModelName);
|
||||||
logger.debug("getStrategyAndFunnel: OpenAI response received. Length: {} chars",
|
logger.debug("getStrategyAndFunnel: OpenAI response received. Length: {} chars",
|
||||||
jsonResponse != null ? jsonResponse.length() : 0);
|
jsonResponse != null ? jsonResponse.length() : 0);
|
||||||
|
|
||||||
@@ -1713,11 +1746,16 @@ public class MarketingAnalysisService {
|
|||||||
// Exponential backoff for 429 errors or empty responses
|
// Exponential backoff for 429 errors or empty responses
|
||||||
if (i < maxAttempts) {
|
if (i < maxAttempts) {
|
||||||
long delayMs;
|
long delayMs;
|
||||||
if (is429Error || (last == null && i < maxAttempts)) {
|
if (is429Error) {
|
||||||
// Exponential backoff: 2s, 4s, 8s
|
// Увеличенные задержки для 429 ошибок: 10s, 20s (приоритет стабильности)
|
||||||
delayMs = (long) Math.pow(2, i) * 1000;
|
delayMs = i * 10000; // 10 секунд для первой попытки, 20 секунд для второй
|
||||||
logger.info("Waiting {}ms before retry (attempt {}/{}) for section '{}' due to {}",
|
logger.info("Waiting {}ms before retry (attempt {}/{}) for section '{}' due to 429 rate limit",
|
||||||
delayMs, i, maxAttempts, sectionId, is429Error ? "429 rate limit" : "empty response");
|
delayMs, i, maxAttempts, sectionId);
|
||||||
|
} else if (last == null && i < maxAttempts) {
|
||||||
|
// Для пустых ответов используем стандартную экспоненциальную задержку
|
||||||
|
delayMs = (long) Math.pow(2, i) * 1000; // 2s, 4s, 8s
|
||||||
|
logger.info("Waiting {}ms before retry (attempt {}/{}) for section '{}' due to empty response",
|
||||||
|
delayMs, i, maxAttempts, sectionId);
|
||||||
} else {
|
} else {
|
||||||
// Small delay for other errors
|
// Small delay for other errors
|
||||||
delayMs = 250L;
|
delayMs = 250L;
|
||||||
|
|||||||
Reference in New Issue
Block a user