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

Persist Conversation History #7

Closed
winxalex opened this issue Feb 28, 2024 · 1 comment
Closed

Persist Conversation History #7

winxalex opened this issue Feb 28, 2024 · 1 comment
Labels
good first issue Good for newcomers question Further information is requested

Comments

@winxalex
Copy link

winxalex commented Feb 28, 2024

I've done web api fast api/uvcorn, and have dictionary that keep ChatSession by cid. This way I can call web api with cid and continue chat session. But if I restart server I can't restore the chat session. If I create new ChatSession with cid (i've written down on paper for test),

 print("create new chat_session with conversation id")
                # create new chat_session with conversation id
                cookies=extract_bard_cookie(True, browser_fn=browser_cookie3.brave) 
                Secure_1PSID = cookies["__Secure-1PSID"]
                Secure_1PSIDTS =cookies["__Secure-1PSIDTS"]
               
                client = GeminiClient(Secure_1PSID, Secure_1PSIDTS, proxy=None)
                await client.init(timeout=30)
               
                chat_session=client.start_chat()
               
                chat_session.cid=conversation_id
               
                gemini_chat_session_dict[conversation_id]=chat_session

This will start new session on same cid (I can see that is browser), all previous history will be erased. Please advice is it possible to have similar functionality as in browser, so I can later continue with the session. Don't know if would work if I serialised pickle the chat session and unpickle later. I think also SNlM0e or access token should be restored and kept for the session

@HanaokaYuzu HanaokaYuzu added the question Further information is requested label Feb 28, 2024
@HanaokaYuzu
Copy link
Owner

To retrieve conversation history, you must provide all 3 values of cid, rid and rcid. They are stored in ChatSession.metadata and will be automatically updated every time after ChatSession.send_message() is called.

Try the following code instead:

# Restore chat session from your record
chat_session=client.start_chat(metadata=gemini_chat_session_dict[conversation_id])

# Metadata will be updated after sending message
await chat_session.send_message("...")

# Update the stored metadata
gemini_chat_session_dict[conversation_id]=chat_session.metadata

@HanaokaYuzu HanaokaYuzu changed the title Persist ChatSession after shut down. Persist Conversation History Mar 3, 2024
@HanaokaYuzu HanaokaYuzu added the good first issue Good for newcomers label Mar 3, 2024
@HanaokaYuzu HanaokaYuzu pinned this issue Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants