Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files
app/api/generate-ai-code-stream/route.ts
CHANGED
|
@@ -1282,6 +1282,8 @@ It's better to have 3 complete files than 10 incomplete files.`
|
|
| 1282 |
} catch (streamError: any) {
|
| 1283 |
console.error(`[generate-ai-code-stream] Error calling streamText (attempt ${retryCount + 1}/${maxRetries + 1}):`, streamError);
|
| 1284 |
|
|
|
|
|
|
|
| 1285 |
const isRetryableError = streamError.message?.includes('Service unavailable') ||
|
| 1286 |
streamError.message?.includes('rate limit') ||
|
| 1287 |
streamError.message?.includes('timeout');
|
|
@@ -1299,11 +1301,17 @@ It's better to have 3 complete files than 10 incomplete files.`
|
|
| 1299 |
// Wait before retry with exponential backoff
|
| 1300 |
await new Promise(resolve => setTimeout(resolve, retryCount * 2000));
|
| 1301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1302 |
} else {
|
| 1303 |
// Final error, send to user
|
| 1304 |
await sendProgress({
|
| 1305 |
type: 'error',
|
| 1306 |
-
message: `Failed to initialize ${isGoogle ? 'Gemini' : isAnthropic ? 'Claude' : isOpenAI ? 'GPT-5' : '
|
| 1307 |
});
|
| 1308 |
|
| 1309 |
// If this is a Google model error, provide helpful info
|
|
|
|
| 1282 |
} catch (streamError: any) {
|
| 1283 |
console.error(`[generate-ai-code-stream] Error calling streamText (attempt ${retryCount + 1}/${maxRetries + 1}):`, streamError);
|
| 1284 |
|
| 1285 |
+
// Check if this is a Groq service unavailable error
|
| 1286 |
+
const isGroqServiceError = isKimiGroq && streamError.message?.includes('Service unavailable');
|
| 1287 |
const isRetryableError = streamError.message?.includes('Service unavailable') ||
|
| 1288 |
streamError.message?.includes('rate limit') ||
|
| 1289 |
streamError.message?.includes('timeout');
|
|
|
|
| 1301 |
// Wait before retry with exponential backoff
|
| 1302 |
await new Promise(resolve => setTimeout(resolve, retryCount * 2000));
|
| 1303 |
|
| 1304 |
+
// If Groq fails, try switching to a fallback model
|
| 1305 |
+
if (isGroqServiceError && retryCount === maxRetries) {
|
| 1306 |
+
console.log('[generate-ai-code-stream] Groq service unavailable, falling back to GPT-4');
|
| 1307 |
+
streamOptions.model = openai('gpt-4-turbo');
|
| 1308 |
+
actualModel = 'gpt-4-turbo';
|
| 1309 |
+
}
|
| 1310 |
} else {
|
| 1311 |
// Final error, send to user
|
| 1312 |
await sendProgress({
|
| 1313 |
type: 'error',
|
| 1314 |
+
message: `Failed to initialize ${isGoogle ? 'Gemini' : isAnthropic ? 'Claude' : isOpenAI ? 'GPT-5' : isKimiGroq ? 'Kimi (Groq)' : 'Groq'} streaming: ${streamError.message}`
|
| 1315 |
});
|
| 1316 |
|
| 1317 |
// If this is a Google model error, provide helpful info
|
app/api/scrape-url-enhanced/route.ts
CHANGED
|
@@ -18,7 +18,7 @@ function sanitizeQuotes(text: string): string {
|
|
| 18 |
|
| 19 |
export async function POST(request: NextRequest) {
|
| 20 |
try {
|
| 21 |
-
console.log('---
|
| 22 |
const { url } = await request.json();
|
| 23 |
|
| 24 |
if (!url) {
|
|
|
|
| 18 |
|
| 19 |
export async function POST(request: NextRequest) {
|
| 20 |
try {
|
| 21 |
+
console.log('--- APPLYING COMBINED FIX V1 ---');
|
| 22 |
const { url } = await request.json();
|
| 23 |
|
| 24 |
if (!url) {
|
lib/ai/provider-manager.ts
CHANGED
|
@@ -63,6 +63,9 @@ function getOrCreateClient(provider: ProviderName, apiKey?: string, baseURL?: st
|
|
| 63 |
case 'google':
|
| 64 |
client = createGoogleGenerativeAI({ apiKey: effective.apiKey || getEnvDefaults('google').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('google').baseURL });
|
| 65 |
break;
|
|
|
|
|
|
|
|
|
|
| 66 |
default:
|
| 67 |
client = createOpenAI({ apiKey: effective.apiKey || getEnvDefaults('helmholtz').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('helmholtz').baseURL });
|
| 68 |
}
|
|
|
|
| 63 |
case 'google':
|
| 64 |
client = createGoogleGenerativeAI({ apiKey: effective.apiKey || getEnvDefaults('google').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('google').baseURL });
|
| 65 |
break;
|
| 66 |
+
case 'helmholtz':
|
| 67 |
+
client = createOpenAI({ apiKey: effective.apiKey || getEnvDefaults('helmholtz').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('helmholtz').baseURL });
|
| 68 |
+
break;
|
| 69 |
default:
|
| 70 |
client = createOpenAI({ apiKey: effective.apiKey || getEnvDefaults('helmholtz').apiKey, baseURL: effective.baseURL ?? getEnvDefaults('helmholtz').baseURL });
|
| 71 |
}
|