Skip to content

fix TypeError in count_tokens & count_tokens_async #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2023

Conversation

Andy963
Copy link
Contributor

@Andy963 Andy963 commented Dec 15, 2023

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

Description of the change

Motivation

Type of change

Choose one: (Bug fix | Feature request | Documentation | Other)

Checklist

  • [x ] I have performed a self-review of my code.
  • [x ] I have added detailed comments to my code where applicable.
  • [x ] I have verified that my change does not break existing code.
  • [x ] My PR is based on the latest changes of the main branch (if unsure, please run git pull --rebase upstream main).
  • [x ] I am familiar with the Google Style Guide for the language I have coded in.
  • [x ] I have read through the Contributing Guide and signed the Contributor License Agreement.

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
@Andy963 Andy963 requested a review from a team as a code owner December 15, 2023 08:18
Copy link

google-cla bot commented Dec 15, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added status:awaiting review PR awaiting review from a maintainer component:python sdk Issue/PR related to Python SDK labels Dec 15, 2023
@better629
Copy link

hhh find the same problem with you, but you submit the issue before I did.

@markmcd
Copy link
Member

markmcd commented Dec 15, 2023

We need the CLA signed before we can merge this.

@Andy963
Copy link
Contributor Author

Andy963 commented Dec 15, 2023

We need the CLA signed before we can merge this.

signed

@markmcd
Copy link
Member

markmcd commented Dec 15, 2023

Thanks for the contribution :)

@markmcd
Copy link
Member

markmcd commented Dec 15, 2023

@MarkDaoust - I think this is worth a new package release, wdyt?

@markmcd markmcd merged commit 2bdec6a into google-gemini:main Dec 15, 2023
@github-actions github-actions bot removed the status:awaiting review PR awaiting review from a maintainer label Dec 15, 2023

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe here should be self._async_client.count_tokens

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sending a PR for this, thanks.

@MarkDaoust
Copy link
Collaborator

@MarkDaoust - I think this is worth a new package release, wdyt?

Yes, I'm planning to release a 0.3.2 Monday. After #120 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants