@adminforth/completion-adapter-google-gemini 2.0.2 → 2.0.4
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/dist/index.js +15 -2
- package/index.ts +16 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import pRetry from 'p-retry';
|
|
|
12
12
|
import { logger } from "adminforth";
|
|
13
13
|
export default class CompletionAdapterGoogleGemini {
|
|
14
14
|
constructor(options) {
|
|
15
|
-
this.complete = (content_1, ...args_1) => __awaiter(this, [content_1, ...args_1], void 0, function* (content, stop = ["."], maxTokens = 50) {
|
|
15
|
+
this.complete = (content_1, ...args_1) => __awaiter(this, [content_1, ...args_1], void 0, function* (content, stop = ["."], maxTokens = 50, outputSchema) {
|
|
16
16
|
const ai = new GoogleGenAI({
|
|
17
17
|
apiKey: this.options.geminiApiKey,
|
|
18
18
|
});
|
|
@@ -22,7 +22,7 @@ export default class CompletionAdapterGoogleGemini {
|
|
|
22
22
|
const response = yield ai.models.generateContent({
|
|
23
23
|
model: this.options.model || "gemini-3-flash-preview",
|
|
24
24
|
contents: content,
|
|
25
|
-
config: Object.assign({ maxOutputTokens: maxTokens }, this.options.extraRequestBodyParameters),
|
|
25
|
+
config: Object.assign({ responseJsonSchema: outputSchema ? outputSchema : undefined, maxOutputTokens: maxTokens }, this.options.extraRequestBodyParameters),
|
|
26
26
|
});
|
|
27
27
|
logger.debug(`Google Gemini SUCCESSFUL API response: ${response}`);
|
|
28
28
|
return {
|
|
@@ -49,4 +49,17 @@ export default class CompletionAdapterGoogleGemini {
|
|
|
49
49
|
throw new Error("geminiApiKey is required");
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
measureTokensCount(content) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
// Implement token counting logic here
|
|
55
|
+
const ai = new GoogleGenAI({
|
|
56
|
+
apiKey: this.options.geminiApiKey,
|
|
57
|
+
});
|
|
58
|
+
const countTokensResponse = yield ai.models.countTokens({
|
|
59
|
+
model: "gemini-2.0-flash",
|
|
60
|
+
contents: content,
|
|
61
|
+
});
|
|
62
|
+
return countTokensResponse.totalTokens;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
52
65
|
}
|
package/index.ts
CHANGED
|
@@ -19,7 +19,21 @@ export default class CompletionAdapterGoogleGemini
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
async measureTokensCount(content: string): Promise<number> {
|
|
23
|
+
// Implement token counting logic here
|
|
24
|
+
const ai = new GoogleGenAI({
|
|
25
|
+
apiKey: this.options.geminiApiKey,
|
|
26
|
+
});
|
|
27
|
+
const countTokensResponse = await ai.models.countTokens({
|
|
28
|
+
model: "gemini-2.0-flash",
|
|
29
|
+
contents: content,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return countTokensResponse.totalTokens;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
complete = async (content: string, stop = ["."], maxTokens = 50, outputSchema?: any): Promise<{
|
|
23
37
|
content?: string;
|
|
24
38
|
finishReason?: string;
|
|
25
39
|
error?: string;
|
|
@@ -36,6 +50,7 @@ export default class CompletionAdapterGoogleGemini
|
|
|
36
50
|
model: this.options.model || "gemini-3-flash-preview",
|
|
37
51
|
contents: content,
|
|
38
52
|
config: {
|
|
53
|
+
responseJsonSchema: outputSchema ? outputSchema : undefined,
|
|
39
54
|
maxOutputTokens: maxTokens,
|
|
40
55
|
...this.options.extraRequestBodyParameters,
|
|
41
56
|
},
|