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

Reuse a previous chat session #30

Closed mdatiqmazumder closed 2 months ago

mdatiqmazumder commented 2 months ago

i want to reuse previour chat session...i dont understant how to do it or how i can use rcid.please help me

dsdanielpark commented 2 months ago

I'm not entirely clear on your use case and objectives. I'm unsure if this will work, but you can try it. Alternatively, you could save the properties of the session and transfer them. The only thing you need to do is modify it by adding the reqid.

from gemini import Gemini

client = Gemini(cookies=cookies)

client.generate_content("Hi, gemini?")

# Save the params
saved_sid = client ._sid # session id
saved_rcid = client ._rcid   # response candidate id
saved_rid = client ._rid # response id
saved_cid = client ._cid   # candidate id
saved_reqid = cliend._reqid + 100000 # request id

# Try to use same session

client = Gemini(cookies=cookies)

client ._sid = saved_sid 
client ._rcid = saved_rcid
client ._rid = saved_rid 
client ._cid = saved_cid
cliend._reqid = saved_reqid

client.generate_content("Hi, what was my last prompt?")