Skip to content

Commit

Permalink
fix TypeError in count_tokens & count_tokens_async (#123)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andy963 authored Dec 15, 2023
1 parent c6688b7 commit 2bdec6a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions google/generativeai/generative_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ def count_tokens(
self, contents: content_types.ContentsType
) -> glm.CountTokensResponse:
contents = content_types.to_contents(contents)
return self._client.count_tokens(self.model_name, contents)
return self._client.count_tokens(model=self.model_name, contents=contents)

async def count_tokens_async(
self, contents: content_types.ContentsType
) -> glm.CountTokensResponse:
contents = content_types.to_contents(contents)
return await self._client.count_tokens(self.model_name, contents)
return await self._client.count_tokens(model=self.model_name, contents=contents)
# fmt: on

def start_chat(
Expand Down

0 comments on commit 2bdec6a

Please sign in to comment.