Skip to content

Commit 654bd48

Browse files
authored
Support getNumTokens for ChatGoogleGenerativeAI (#4149)
1 parent c318fc5 commit 654bd48

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/components/nodes/chatmodels/ChatGoogleGenerativeAI/FlowiseChatGoogleGenerativeAI.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ class LangchainChatGoogleGenerativeAI
209209
}
210210
}
211211

212+
async getNumTokens(prompt: BaseMessage[]) {
213+
const contents = convertBaseMessagesToContent(prompt, this._isMultimodalModel)
214+
const { totalTokens } = await this.client.countTokens({ contents })
215+
return totalTokens
216+
}
217+
212218
async _generateNonStreaming(
213219
prompt: Content[],
214220
options: this['ParsedCallOptions'],

0 commit comments

Comments
 (0)