Skip to content
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

count_tokens method not working #151

Closed
SaratChandraV opened this issue Dec 22, 2023 · 2 comments
Closed

count_tokens method not working #151

SaratChandraV opened this issue Dec 22, 2023 · 2 comments
Labels
component:python sdk Issue/PR related to Python SDK type:bug Something isn't working

Comments

@SaratChandraV
Copy link

Description of the bug:

the count_tokens method in the genai.GenerativeModel class is not working. it is showing
Error:
count_tokens() takes from 1 to 2 positional arguments but 3 were given

Actual vs expected behavior:

genai.configure(api_key=api_key.GOOGLE_API_KEY)
model = genai.GenerativeModel('gemini-pro')
#test apikey
for m in genai.list_models():
  if 'generateContent' in m.supported_generation_methods:
    print(m.name)
response = model.generate_content("Is sky blue?")
print(response.text)
print(model.count_tokens("hello"))

Output:

models/gemini-pro
models/gemini-pro-vision
In general, the sky appears blue during the day due to a phenomenon known as Rayleigh scattering. Here's why:

* **Sunlight:** Sunlight consists of a range of colors, including blue, green, yellow, orange, red, and violet.

* **Wavelength:** Each color of light has a specific wavelength. Blue light has a shorter wavelength compared to other colors in the visible spectrum.

* **Rayleigh Scattering:** When sunlight enters the Earth's atmosphere, it interacts with molecules of nitrogen and oxygen. These molecules are much smaller than the wavelength of visible light. When sunlight encounters these molecules, it undergoes a process called Rayleigh scattering.

* **Scattering of Blue Light:** Rayleigh scattering causes the shorter wavelength blue light to scatter more than other colors of light. This means that blue light is scattered in all directions, including towards our eyes. As a result, we perceive the sky as blue during the daytime.

* **Other Factors:** The exact shade of blue we see can vary depending on factors such as the time of day, weather conditions, and the presence of particles in the atmosphere like dust, smoke, or clouds. These factors can affect the amount of scattering and the intensity of the blue color.

It's important to note that the sky is not inherently blue. The blue color we see is a result of the interaction between sunlight and the Earth's atmosphere. This phenomenon is what gives us our beautiful blue skies during the daytime.

{
	"name": "TypeError",
	"message": "count_tokens() takes from 1 to 2 positional arguments but 3 were given",
	"stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[21], line 9
      7 response = model.generate_content(\"Is sky blue?\")
      8 print(response.text)
----> 9 print(model.count_tokens(\"hello\"))

File ~/Library/Python/3.9/lib/python/site-packages/google/generativeai/generative_models.py:278, in GenerativeModel.count_tokens(self, contents)
    274 def count_tokens(
    275     self, contents: content_types.ContentsType
    276 ) -> glm.CountTokensResponse:
    277     contents = content_types.to_contents(contents)
--> 278     return self._client.count_tokens(self.model_name, contents)

TypeError: count_tokens() takes from 1 to 2 positional arguments but 3 were given"
}

Any other information you'd like to share?

No response

@SaratChandraV SaratChandraV added component:python sdk Issue/PR related to Python SDK type:bug Something isn't working labels Dec 22, 2023
@Andy963
Copy link
Contributor

Andy963 commented Dec 22, 2023

@SaratChandraV update to 0.32 ,this bug was fixed

@SaratChandraV
Copy link
Author

@Andy963 Thanks the issue is resolved after upgraded to current version of 0.3.2. Closing the issue

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 type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants