Question on initiating interactive chat in API docs

Hi everyone!
I’m confused about on API documentation on Build an interactive chat
Gemini API Docs - Build an interactive chat

My goal is to have multiple rounds of questions and responses for my app users. From the documentation, Gemini’s startChat seems to require some initial input, to establish the chat session. How do I initiate an interactive chat with the Gemini API using startChat without any previous messages as context? With OpenAI, I can simply pass an empty array to start a fresh chat. Is there an equivalent way to do this with Gemini?

This is the detailed documentation of the ChatSession object. It explains the history attribute within ChatSession, which stores the conversation history.
github generative-ai-python/docs/api/google/generativeai/ChatSession.md

Thank you in advance for your insight!

Welcome to the forum. The history can be empty the first time your app invokes startChat, and most cookbook examples do exactly that, or don’t even bother to pass history which then defaults to an empty list.

There is a scenario where history is non-empty when starting a chat session: when (today) you are continuing a chat session from, say, last week. That involves retrieving the history from a persistent object store and passing the resurrected history as a parameter to startChat to continue from where it was last week.

Hope that helps.

1 Like