ai-codegen-cli-vrk 2.0.8 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/aiClient.js +11 -9
package/package.json
CHANGED
package/src/aiClient.js
CHANGED
|
@@ -7,10 +7,14 @@ export function setApiKey(apiKey) {
|
|
|
7
7
|
genAI = new GoogleGenerativeAI(apiKey.trim());
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Robust model discovery. Tries newer Flash models first.
|
|
12
|
+
*/
|
|
10
13
|
async function getWorkingModel() {
|
|
11
14
|
if (activeModel) return activeModel;
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
// Added 2.0 Flash to the list
|
|
17
|
+
const modelNames = ["gemini-1.5-flash", "gemini-2.0-flash-exp", "gemini-1.5-flash-latest", "gemini-pro"];
|
|
14
18
|
const apiVersions = ["v1beta", "v1"];
|
|
15
19
|
|
|
16
20
|
let lastError = null;
|
|
@@ -19,7 +23,7 @@ async function getWorkingModel() {
|
|
|
19
23
|
for (const name of modelNames) {
|
|
20
24
|
try {
|
|
21
25
|
const m = genAI.getGenerativeModel({ model: name }, { apiVersion: ver });
|
|
22
|
-
//
|
|
26
|
+
// Verification call
|
|
23
27
|
await m.generateContent({
|
|
24
28
|
contents: [{ role: "user", parts: [{ text: "hi" }] }],
|
|
25
29
|
generationConfig: { maxOutputTokens: 1 }
|
|
@@ -28,9 +32,7 @@ async function getWorkingModel() {
|
|
|
28
32
|
return m;
|
|
29
33
|
} catch (err) {
|
|
30
34
|
lastError = err;
|
|
31
|
-
// If it's a 404, this combination is invalid; try next.
|
|
32
35
|
if (err.message.includes("404") || err.message.includes("not found")) continue;
|
|
33
|
-
// If it's an Auth error, stop and throw it.
|
|
34
36
|
if (err.message.includes("API key not valid") || err.message.includes("401")) {
|
|
35
37
|
throw new Error("Invalid API Key. Please check it at aistudio.google.com");
|
|
36
38
|
}
|
|
@@ -38,7 +40,7 @@ async function getWorkingModel() {
|
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
throw new Error(`Connection Failed.
|
|
43
|
+
throw new Error(`Connection Failed. Google's server rejected the model request. Error: ${lastError?.message}`);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export async function generateFullProject(task, tests, retryCount = 0) {
|
|
@@ -46,7 +48,6 @@ export async function generateFullProject(task, tests, retryCount = 0) {
|
|
|
46
48
|
const model = await getWorkingModel();
|
|
47
49
|
|
|
48
50
|
const prompt = `
|
|
49
|
-
You are an expert automated coding exam solver.
|
|
50
51
|
Generate the ENTIRE project in a SINGLE response.
|
|
51
52
|
Strictly pass all test cases.
|
|
52
53
|
|
|
@@ -74,10 +75,11 @@ ${tests}
|
|
|
74
75
|
return text.replace(/```[a-z]*\n([\s\S]*?)\n```/gi, "$1").trim();
|
|
75
76
|
|
|
76
77
|
} catch (error) {
|
|
77
|
-
// Handle Overloaded (503) or Rate Limit (429)
|
|
78
|
+
// Handle Overloaded (503) or Rate Limit (429) - Critical for Free Tier
|
|
78
79
|
if ((error.message.includes("503") || error.message.includes("429")) && retryCount < 5) {
|
|
79
|
-
console.log(`..... (Server busy,
|
|
80
|
-
|
|
80
|
+
console.log(`..... (Quota hit or Server busy, waiting to retry ${retryCount + 1}/5)`);
|
|
81
|
+
// Wait 15 seconds to safely clear the Free Tier 15-RPM limit
|
|
82
|
+
await new Promise(r => setTimeout(r, 15000));
|
|
81
83
|
return generateFullProject(task, tests, retryCount + 1);
|
|
82
84
|
}
|
|
83
85
|
throw error;
|