Passing context to the model

#16
by Mahendranath - opened

How to pass the context to the model along with the input text? What should be the structure of messages?

Hi @Mahendranath -

Thanks for reaching out to us!

For google/translategemma-4b-it , the model expects a structured message format with only user and assistant roles and a fixed schema. Each user message must include a single content entry with fields such as type where the property where the value must be either text or image, source_lang_code, target_lang_code.

The content list entry should provide either a url property, if the entry's type is image, from which the image will be loaded or a text property, if the entry's type is text, containing only the text to translate.

Example:

messages = [
    {
        "role": "user",
        "content": [
         {
                "type": "text",
                "source_lang_code": "cs",
                "target_lang_code": "de-DE",
                "text": "V nejhorším případě i k prasknutí čočky.",
            }
       ],
    }
]

Sign up or log in to comment