@adminforth/completion-adapter-google-gemini 2.0.3 → 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 +13 -0
- package/index.ts +14 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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,6 +19,20 @@ export default class CompletionAdapterGoogleGemini
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
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
|
+
|
|
22
36
|
complete = async (content: string, stop = ["."], maxTokens = 50, outputSchema?: any): Promise<{
|
|
23
37
|
content?: string;
|
|
24
38
|
finishReason?: string;
|