How can I start a new chat with custom chat history in the new Google Gen AI SDK? (python)

In the previous version, we could start a new chat using chat:
chat = model.start_chat(history=chat_history) where, we would add the history as a parameter or leave it blank.

But in the new sdk,
chat = client.chats.create(
model=MODEL_ID,
config=types.GenerateContentConfig(
system_instruction=system_instruction,
temperature=0.5,
),
)
There is no parameter for chat history.

Hi,

Welcome to the forum.

According to the source code on GitHub

There is an optional parameter history that you could use.

Hope this helps.

2 Likes

What is the type of the Content in

history: Optional[list[Content]] = None,

Hi @Wonder-David_Efe

It’s a pre-defined type that can have one or multiple various parts according to the documentation.
Most likely it will be messages with alternating roles - user and model - to mimic a conversation between the user’s prompts and the model’s response.

See documentation for more. Or use AI Studio with a Chat and a conversation. Then hit the “Get code” button to see how it is structured.

Cheers