Skip to content

Commit 2bdec6a

Browse files
authored
fix TypeError in count_tokens & count_tokens_async (#123)
async def count_tokens( self, request: Optional[Union[generative_service.CountTokensRequest, dict]] = None, *, model: Optional[str] = None, contents: Optional[MutableSequence[content.Content]] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, metadata: Sequence[Tuple[str, str]] = (), if you don't use keyword args : model=model, contents=contents, but position args, this will lead to : TypeError: count_tokens() takes from 1 to 2 positional arguments but 3 were given
1 parent c6688b7 commit 2bdec6a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

google/generativeai/generative_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ def count_tokens(
275275
self, contents: content_types.ContentsType
276276
) -> glm.CountTokensResponse:
277277
contents = content_types.to_contents(contents)
278-
return self._client.count_tokens(self.model_name, contents)
278+
return self._client.count_tokens(model=self.model_name, contents=contents)
279279

280280
async def count_tokens_async(
281281
self, contents: content_types.ContentsType
282282
) -> glm.CountTokensResponse:
283283
contents = content_types.to_contents(contents)
284-
return await self._client.count_tokens(self.model_name, contents)
284+
return await self._client.count_tokens(model=self.model_name, contents=contents)
285285
# fmt: on
286286

287287
def start_chat(

0 commit comments

Comments
 (0)