How to share conversation?

Lets say, I am having long conversation with gemini, suddenly I feel this whole conversation I need to share with my team, so that they ask further question to gemini, as long conversation==long context.

I know there is a way, we can do it by storing all the messages and add those via:

val chat = generativeModel.startChat(
    history = listOf(
        content(role = "user") { text("Hello, I have 2 dogs in my house.") },
        content(role = "model") { text("Great to meet you. What would you like to know?") }
    )
)

Its efficient as long as all inputs are in text format, but what if it also has image and video. It will be huge size of data for long conversation.

Is there any other way I can share the long context?

The most efficient way to reference media is to use a fileData part which references the media through a URL.

If you’re using the AI Studio API, you need to use the File API AI, which is only permitted to the same API Key. But if you’re using Vertex AI, it needs to be a file in Google Cloud Storage.

yeah its one of the way, but in this approach also, gemini will process the video from scratch, and that will cost tokens, which is unnecessary for an already processed video. For long video token cost will be huge.

Well… yes and no.

If you use fileData, it doesn’t process the video from scratch - it has already converted the video to tokens and won’t have to do that again. And you don’t have to re-upload it each time.

It will, however, have to go through the tokens (both the text tokens and the tokens from the video - by that time the model doesn’t care) to do text completion. That is how these models work.

If you have some base portion (such as system instructions and a video) that is in front of all of your conversations, you can take a look at context caching. This allows you to pre-store part of the conversation and then continue the convesation from that point in the future with savings in cost and time under some circumstances. (Take a careful look at the cost, however - this isn’t good to just store it after every exchange.)

1 Like