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"
}
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:
Output:
Any other information you'd like to share?
No response