Class ChatSession (1.39.0)

ChatSession(
    model: vertexai.generative_models._generative_models._GenerativeModel,
    *,
    history: typing.Optional[
        typing.List[vertexai.generative_models._generative_models.Content]
    ] = None,
    raise_on_blocked: bool = True
)

Chat session holds the chat history.

Methods

send_message

send_message(
    content: typing.Union[
        str,
        vertexai.generative_models._generative_models.Image,
        vertexai.generative_models._generative_models.Part,
        typing.List[
            typing.Union[
                str,
                vertexai.generative_models._generative_models.Image,
                vertexai.generative_models._generative_models.Part,
            ]
        ],
    ],
    *,
    generation_config: typing.Optional[
        typing.Union[
            vertexai.generative_models._generative_models.GenerationConfig,
            typing.Dict[str, typing.Any],
        ]
    ] = None,
    safety_settings: typing.Optional[
        typing.Union[
            typing.List[google.cloud.aiplatform_v1beta1.types.content.SafetySetting],
            typing.Dict[
                google.cloud.aiplatform_v1beta1.types.content.HarmCategory,
                google.cloud.aiplatform_v1beta1.types.content.SafetySetting.HarmBlockThreshold,
            ],
        ]
    ] = None,
    tools: typing.Optional[
        typing.List[vertexai.generative_models._generative_models.Tool]
    ] = None,
    stream: bool = False
) -> typing.Union[
    vertexai.generative_models._generative_models.GenerationResponse,
    typing.Iterable[vertexai.generative_models._generative_models.GenerationResponse],
]

Generates content.

Parameter
Name Description
content typing.Union[str, Image, Part, typing.List[typing.Union[str, Image, Part]]]

Content to send to the model. Supports a value that can be converted to a Part or a list of such values. Supports * str, Image, Part, * List[Union[str, Image, Part]],

Exceptions
Type Description
ResponseBlockedError If the response was blocked.

send_message_async

send_message_async(
    content: typing.Union[
        str,
        vertexai.generative_models._generative_models.Image,
        vertexai.generative_models._generative_models.Part,
        typing.List[
            typing.Union[
                str,
                vertexai.generative_models._generative_models.Image,
                vertexai.generative_models._generative_models.Part,
            ]
        ],
    ],
    *,
    generation_config: typing.Optional[
        typing.Union[
            vertexai.generative_models._generative_models.GenerationConfig,
            typing.Dict[str, typing.Any],
        ]
    ] = None,
    safety_settings: typing.Optional[
        typing.Union[
            typing.List[google.cloud.aiplatform_v1beta1.types.content.SafetySetting],
            typing.Dict[
                google.cloud.aiplatform_v1beta1.types.content.HarmCategory,
                google.cloud.aiplatform_v1beta1.types.content.SafetySetting.HarmBlockThreshold,
            ],
        ]
    ] = None,
    tools: typing.Optional[
        typing.List[vertexai.generative_models._generative_models.Tool]
    ] = None,
    stream: bool = False
) -> typing.Union[
    typing.Awaitable[vertexai.generative_models._generative_models.GenerationResponse],
    typing.Awaitable[
        typing.AsyncIterable[
            vertexai.generative_models._generative_models.GenerationResponse
        ]
    ],
]

Generates content asynchronously.

Parameter
Name Description
content typing.Union[str, Image, Part, typing.List[typing.Union[str, Image, Part]]]

Content to send to the model. Supports a value that can be converted to a Part or a list of such values. Supports * str, Image, Part, * List[Union[str, Image, Part]],

Exceptions
Type Description
ResponseBlockedError If the response was blocked.