refine ui further
This commit is contained in:
@@ -1294,26 +1294,59 @@ It's better to have 3 complete files than 10 incomplete files.`
|
||||
}
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = await streamText(streamOptions);
|
||||
} catch (streamError) {
|
||||
console.error('[generate-ai-code-stream] Error calling streamText:', streamError);
|
||||
|
||||
// Send specific error for debugging
|
||||
await sendProgress({
|
||||
type: 'error',
|
||||
message: `Failed to initialize ${isGoogle ? 'Gemini' : isAnthropic ? 'Claude' : isOpenAI ? 'GPT-5' : 'Groq'} streaming: ${(streamError as Error).message}`
|
||||
});
|
||||
|
||||
// If this is a Google model error, provide helpful info
|
||||
if (isGoogle) {
|
||||
await sendProgress({
|
||||
type: 'info',
|
||||
message: 'Tip: Make sure your GEMINI_API_KEY is set correctly and has proper permissions.'
|
||||
});
|
||||
let retryCount = 0;
|
||||
const maxRetries = 2;
|
||||
|
||||
while (retryCount <= maxRetries) {
|
||||
try {
|
||||
result = await streamText(streamOptions);
|
||||
break; // Success, exit retry loop
|
||||
} catch (streamError: any) {
|
||||
console.error(`[generate-ai-code-stream] Error calling streamText (attempt ${retryCount + 1}/${maxRetries + 1}):`, streamError);
|
||||
|
||||
// Check if this is a Groq service unavailable error
|
||||
const isGroqServiceError = isKimiGroq && streamError.message?.includes('Service unavailable');
|
||||
const isRetryableError = streamError.message?.includes('Service unavailable') ||
|
||||
streamError.message?.includes('rate limit') ||
|
||||
streamError.message?.includes('timeout');
|
||||
|
||||
if (retryCount < maxRetries && isRetryableError) {
|
||||
retryCount++;
|
||||
console.log(`[generate-ai-code-stream] Retrying in ${retryCount * 2} seconds...`);
|
||||
|
||||
// Send progress update about retry
|
||||
await sendProgress({
|
||||
type: 'info',
|
||||
message: `Service temporarily unavailable, retrying (attempt ${retryCount + 1}/${maxRetries + 1})...`
|
||||
});
|
||||
|
||||
// Wait before retry with exponential backoff
|
||||
await new Promise(resolve => setTimeout(resolve, retryCount * 2000));
|
||||
|
||||
// If Groq fails, try switching to a fallback model
|
||||
if (isGroqServiceError && retryCount === maxRetries) {
|
||||
console.log('[generate-ai-code-stream] Groq service unavailable, falling back to GPT-4');
|
||||
streamOptions.model = openai('gpt-4-turbo');
|
||||
actualModel = 'gpt-4-turbo';
|
||||
}
|
||||
} else {
|
||||
// Final error, send to user
|
||||
await sendProgress({
|
||||
type: 'error',
|
||||
message: `Failed to initialize ${isGoogle ? 'Gemini' : isAnthropic ? 'Claude' : isOpenAI ? 'GPT-5' : isKimiGroq ? 'Kimi (Groq)' : 'Groq'} streaming: ${streamError.message}`
|
||||
});
|
||||
|
||||
// If this is a Google model error, provide helpful info
|
||||
if (isGoogle) {
|
||||
await sendProgress({
|
||||
type: 'info',
|
||||
message: 'Tip: Make sure your GEMINI_API_KEY is set correctly and has proper permissions.'
|
||||
});
|
||||
}
|
||||
|
||||
throw streamError;
|
||||
}
|
||||
}
|
||||
|
||||
throw streamError;
|
||||
}
|
||||
|
||||
// Stream the response and parse in real-time
|
||||
|
||||
Reference in New Issue
Block a user