Inject context in chat functionality

Based on the official documentation, how would you inject context for the model to start the chat? I only have the context available after the beginning of the chat, not beforehand when i create model.

Hi @Asrebo , Welcome to forum.

You can use system instructions to inject the context when defining the model. If you have a large context, you might want to try the Gemini API’s context caching feature. Please refer the Context Caching Quickstart.

Thank you

Hi, you can pass a history collection of messages into the constructor / method as parameter.

1 Like