We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bb330b7 commit d7987beCopy full SHA for d7987be
1 file changed
Tool/Sources/TokenEncoder/GoogleAITokenCounter.swift
@@ -0,0 +1,13 @@
1
+import GoogleGenerativeAI
2
+
3
+public final class GoogleAITokenCounter: TokenCounter {
4
+ let model: GenerativeModel
5
6
+ public init(model: GenerativeModel) {
7
+ self.model = model
8
+ }
9
10
+ public func countToken(text: String) async -> Int {
11
+ (try? await model.countTokens(text))?.totalTokens ?? text.count
12
13
+}
0 commit comments