@3-/aiapi 0.1.44 → 0.1.46
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/gemini.js +14 -11
- package/package.json +1 -1
package/gemini.js
CHANGED
|
@@ -21,7 +21,7 @@ export default (token_li, model = 'gemini-2.5-pro') => {
|
|
|
21
21
|
return _NEXT_TOKEN.next().value;
|
|
22
22
|
};
|
|
23
23
|
return async(text, schema, system, option) => {
|
|
24
|
-
var body, err, error, message, parts, r, retryed, status;
|
|
24
|
+
var body, err, error, json, message, parts, r, retryed, status;
|
|
25
25
|
body = {
|
|
26
26
|
contents: [
|
|
27
27
|
{
|
|
@@ -87,30 +87,33 @@ export default (token_li, model = 'gemini-2.5-pro') => {
|
|
|
87
87
|
} catch (error1) {
|
|
88
88
|
console.warn(text);
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
if (status !== 500) {
|
|
91
|
+
await sleep(1000);
|
|
92
|
+
}
|
|
91
93
|
continue;
|
|
92
94
|
}
|
|
93
95
|
throw new Error(text);
|
|
94
96
|
}
|
|
95
|
-
|
|
97
|
+
json = (await r.json());
|
|
98
|
+
({parts} = json.candidates[0].content);
|
|
99
|
+
if (!parts) {
|
|
100
|
+
console.warn('miss parts', JSON.stringify(json, null, 2));
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
text = parts[0].text;
|
|
96
104
|
if (schema) {
|
|
97
105
|
try {
|
|
98
|
-
|
|
99
|
-
if (!parts) {
|
|
100
|
-
console.warn('miss parts', r.content);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
r = JSON.parse(parts[0].text);
|
|
106
|
+
return JSON.parse(text);
|
|
104
107
|
} catch (error1) {
|
|
105
108
|
err = error1;
|
|
106
|
-
console.error(body,
|
|
109
|
+
console.error(body, text, err);
|
|
107
110
|
if (--retryed <= 0) {
|
|
108
111
|
throw err;
|
|
109
112
|
}
|
|
110
113
|
continue;
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
|
-
return
|
|
116
|
+
return text;
|
|
114
117
|
}
|
|
115
118
|
};
|
|
116
119
|
};
|