dsdanielpark / Gemini-API

The unofficial python package that returns response of Google Gemini through cookie values.
https://pypi.org/project/python-gemini-api/
MIT License
148 stars 11 forks source link

It returns message "maximum recursion depth exceeded" #19

Closed phamxtien closed 3 months ago

phamxtien commented 4 months ago

Describe the bug Gemini returns message "maximum recursion depth exceeded"

Version OS: Ubuntu 23.10 Python: 3.11 Gemini API: 2.0.0 Using proxy: None Legion:

Code

from gemini import Gemini

cookies = {} # I input my cookies here as decribe in README
GeminiClient = Gemini(cookies=cookies)

prompt = "hello, how are you?"
response = GeminiClient.generate_content(prompt)

print(response.response.dict)

Error

It returns "maximum recursion depth exceeded"
I check on gemini.google.com/app, 
it has sent prompt to gemini but not get answer from gemini.google.com/app as below image 
Bard API still runs smooth!

image

dsdanielpark commented 4 months ago

Thank you for reporting.

Please give me tracebacked error message.

cacko commented 4 months ago

looks like it returns attachment instead of text now, response.bin, dunno have not dig much, so sorry if that makes no sense

dsdanielpark commented 4 months ago

Would it still work if I leave the Gemini object as is and only rerun the generate content method? I'll check again tomorrow. I was aware of the bot server change, but since the old bot server was still running, I didn't make the switch, though I'm a bit scared, I'll check it again.

Before posting it on the readme, I'll first post it on this issue page. Since it's difficult to code and check, I'll get back to you within 12 hours!

Thank you.

PushkarOP commented 4 months ago
Traceback (most recent call last):
  File "c:\Users\Divyanshi\Desktop\New\tets.py", line 83, in <module>
    print(geminiultra("What is the capital of France? also show images"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Divyanshi\Desktop\New\tets.py", line 45, in geminiultra
    answer = response.response_dict['candidates']['text']
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Divyanshi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gemini\src\model\output.py", line 47, in response_dict
    return self.response_dict
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\Divyanshi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gemini\src\model\output.py", line 47, in response_dict
    return self.response_dict
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\Divyanshi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gemini\src\model\output.py", line 47, in response_dict
    return self.response_dict
           ^^^^^^^^^^^^^^^^^^
  [Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded
Traceback (most recent call last):
  File "c:\Users\Divyanshi\Desktop\New\tets.py", line 84, in <module>
    print(geminiultra("What is the capital of France? also show images"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\Divyanshi\Desktop\New\tets.py", line 44, in geminiultra
    response = GeminiClient.generate_content(prompt)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Divyanshi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gemini\core.py", line 263, in generate_content
    return self._create_model_output(parsed_response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Divyanshi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gemini\core.py", line 275, in _create_model_output
    candidates = self.collect_candidates(parsed_response)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Divyanshi\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\gemini\core.py", line 308, in collect_candidates
    collected.append(GeminiCandidate(**current))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for GeminiCandidate
code
  value is not a valid list (type=type_error.list)
dsdanielpark commented 4 months ago

Thank you for reporting. I will check this issue ASAP.

phamxtien commented 4 months ago

I just update to Ver 2.2.0 and it still returns "maximum recursion depth exceeded"

dsdanielpark commented 4 months ago

phamxtien The update in Python 3.11 is suspected to cause recursive calls leading to a "recursive exceed" error.

However, recognizing that errors could technically occur in that syntax, I have clarified and corrected it again.

I've made modifications to change the recursive calls in property definitions in GeminiModelOutput. Could you please reinstall the version from GitHub and check again?

pip install git+https://github.com/dsdanielpark/Gemini-API.git

or try to using v2.2.1

phamxtien commented 4 months ago

Thank you for your guide I just get newest source and it still return the same error I will try with python3 3.8

dsdanielpark commented 4 months ago

Are you sure to use print(response.response_dict) ?

Or try to use rint(response.payload)

It seems the issue is related to a property, which might confuse other users. I'm concerned but will fix it as soon as possible. Please keep following the issue for updates; I'll correct it soon and adjust the settings to address the error. In reality, there's still a lot to refactor and implement, but due to a busy schedule, I haven't been able to devote much time to it. Thank you.

phamxtien commented 4 months ago

use print(response.response_dict) ?

I use print(response.response_dict)

dsdanielpark commented 4 months ago

phamxtien

I release v2.2.2. Could you check?

ghost commented 4 months ago

rint(response.payload)

it works, and response format is also changed

{'metadata': ['c_37bce86328f5eb0c', 'r_7ad361e5f2e31296'], 'prompt_class': None, 'prompt_candidates': [], 'candidates': [{'rcid': 'rc_dcc7ef3199425605', 'text': 'The capital of France is Paris. It is a major European city and a global center for art, fashion, gastronomy, and culture. \n[Image of Paris, France] ', 'code': {}, 'web_images': [{'url': 'https://sa.visamiddleeast.com/dam/VCOM/regional/cemea/generic-cemea/travel-with-visa/destinations/paris/marquee-travel-paris-800x450.jpg', 'title': '[Image of Paris, France]', 'alt': 'Paris, France'}], 'generated_images': []}, {'rcid': 'rc_af89988c3898dec1', 'text': 'The capital of France is Paris.  Paris is a major world center for art, fashion, cuisine, and culture.   \n[Image of Paris, France]', 'code': {}, 'web_images': [{'url': 'https://sa.visamiddleeast.com/dam/VCOM/regional/cemea/generic-cemea/travel-with-visa/destinations/paris/marquee-travel-paris-800x450.jpg', 'title': '[Image of 
Paris, France]', 'alt': 'Paris, France'}], 'generated_images': []}, {'rcid': 'rc_daf9c135dc80150a', 'text': "The capital of France is Paris. It's a major European city and a global center for art, fashion, gastronomy, and culture. \n[Image of Paris, France]", 'code': {}, 'web_images': [{'url': 'https://sa.visamiddleeast.com/dam/VCOM/regional/cemea/generic-cemea/travel-with-visa/destinations/paris/marquee-travel-paris-800x450.jpg', 'title': '[Image of Paris, France]', 'alt': 'Paris, France'}], 'generated_images': []}]}
phamxtien commented 3 months ago

phamxtien

I release v2.2.2. Could you check?

Thanks, it runs smooth

dsdanielpark commented 3 months ago

Thank you for reporting! Have a nice day. I will close this issue as complet.