Skip to content

chat

chat(
    application_id: ApplicationId,
    *,
    config_overrides: Optional[QBusinessClientConfig] = None,
    user_id: Optional[UserId] = None,
    user_groups: Optional[UserGroups] = None,
    conversation_id: Optional[ConversationId] = None,
    parent_message_id: Optional[MessageId] = None,
    client_token: Optional[ClientToken] = None,
    input_stream: Optional[Iterator[_ChatInputStream] | _ChatInputStream] = None,
) -> Generator[ChatOutput]

Starts or continues a streaming Amazon Q Business conversation.

Parameters:

  • application_id (ApplicationId) –

    The identifier of the Amazon Q Business application linked to a streaming Amazon Q Business conversation.

  • user_id (Optional[UserId], default: None ) –

    The identifier of the user attached to the chat input.

  • user_groups (Optional[UserGroups], default: None ) –

    The group names that a user associated with the chat input belongs to.

  • conversation_id (Optional[ConversationId], default: None ) –

    The identifier of the Amazon Q Business conversation.

  • parent_message_id (Optional[MessageId], default: None ) –

    The identifier used to associate a user message with a AI generated response.

  • client_token (Optional[ClientToken], default: None ) –

    A token that you provide to identify the chat input.

  • input_stream (Optional[Iterator[_ChatInputStream] | _ChatInputStream], default: None ) –

    The streaming input for the Chat API.

Raises:

  • AccessDeniedException –

    You don't have access to perform this action. Make sure you have the required permission policies and user accounts and try again.

  • ConflictException –

    You are trying to perform an action that conflicts with the current status of your resource. Fix any inconsistencies with your resources and try again.

  • ExternalResourceException –

    An external resource that you configured with your application is returning errors and preventing this operation from succeeding. Fix those errors and try again.

  • InternalServerException –

    An issue occurred with the internal server used for your Amazon Q Business service. Wait some minutes and try again, or contact Support for help.

  • LicenseNotFoundException –

    You don't have permissions to perform the action because your license is inactive. Ask your admin to activate your license and try again after your licence is active.

  • ResourceNotFoundException –

    The application or plugin resource you want to use doesn’t exist. Make sure you have provided the correct resource and try again.

  • ThrottlingException –

    The request was denied due to throttling. Reduce the number of requests and try again.

  • ValidationException –

    The input doesn't meet the constraints set by the Amazon Q Business service. Provide the correct input and try again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_qbusiness/_services/q_business.py
@contextmanager
def chat(
    self,
    application_id: "capo_qbusiness.types.application_id.ApplicationId",
    *,
    config_overrides: Optional[QBusinessClientConfig] = None,
    user_id: Optional["capo_qbusiness.types.user_id.UserId"] = None,
    user_groups: Optional["capo_qbusiness.types.user_groups.UserGroups"] = None,
    conversation_id: Optional[
        "capo_qbusiness.types.conversation_id.ConversationId"
    ] = None,
    parent_message_id: Optional["capo_qbusiness.types.message_id.MessageId"] = None,
    client_token: Optional["capo_qbusiness.types.client_token.ClientToken"] = None,
    input_stream: Optional[
        "Iterator[capo_qbusiness.types.chat_input_stream._ChatInputStream] | capo_qbusiness.types.chat_input_stream._ChatInputStream"
    ] = None,
) -> "Generator[capo_qbusiness.types.chat_output.ChatOutput]":
    """<p>Starts or continues a streaming Amazon Q Business conversation.</p>

    Args:
        application_id: <p>The identifier of the Amazon Q Business application linked to a streaming Amazon Q Business conversation.</p>
        user_id: <p>The identifier of the user attached to the chat input. </p>
        user_groups: <p>The group names that a user associated with the chat input belongs to.</p>
        conversation_id: <p>The identifier of the Amazon Q Business conversation.</p>
        parent_message_id: <p>The identifier used to associate a user message with a AI generated response.</p>
        client_token: <p>A token that you provide to identify the chat input.</p>
        input_stream: <p>The streaming input for the <code>Chat</code> API.</p>

    Raises:
        capo_qbusiness.errors.access_denied_exception.AccessDeniedException: <p> You don't have access to perform this action. Make sure you have the required permission policies and user accounts and try again.</p>
        capo_qbusiness.errors.conflict_exception.ConflictException: <p>You are trying to perform an action that conflicts with the current status of your resource. Fix any inconsistencies with your resources and try again.</p>
        capo_qbusiness.errors.external_resource_exception.ExternalResourceException: <p>An external resource that you configured with your application is returning errors and preventing this operation from succeeding. Fix those errors and try again. </p>
        capo_qbusiness.errors.internal_server_exception.InternalServerException: <p>An issue occurred with the internal server used for your Amazon Q Business service. Wait some minutes and try again, or contact <a href="http://aws.amazon.com/contact-us/">Support</a> for help.</p>
        capo_qbusiness.errors.license_not_found_exception.LicenseNotFoundException: <p>You don't have permissions to perform the action because your license is inactive. Ask your admin to activate your license and try again after your licence is active.</p>
        capo_qbusiness.errors.resource_not_found_exception.ResourceNotFoundException: <p>The application or plugin resource you want to use doesn’t exist. Make sure you have provided the correct resource and try again.</p>
        capo_qbusiness.errors.throttling_exception.ThrottlingException: <p>The request was denied due to throttling. Reduce the number of requests and try again.</p>
        capo_qbusiness.errors.validation_exception.ValidationException: <p>The input doesn't meet the constraints set by the Amazon Q Business service. Provide the correct input and try again.</p>
        capo_qbusiness.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_qbusiness.types.chat_input.ChatInput]",
    ) -> OperationResponse["capo_qbusiness.types.chat_output.ChatOutput"]:
        import capo_qbusiness._operations.expert_q.chat

        output, http_response = capo_qbusiness._operations.expert_q.chat.chat(
            req.options, req.input
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_qbusiness.types.chat_input.ChatInput",
    ) -> dict[str, Any]:
        import capo_qbusiness.types.chat_input

        return capo_qbusiness.types.chat_input.redact_sensitive(input_)

    def _redact_output(
        output: "capo_qbusiness.types.chat_output.ChatOutput",
    ) -> dict[str, Any]:
        import capo_qbusiness.types.chat_output

        return capo_qbusiness.types.chat_output.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "Chat", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_qbusiness.types.chat_input.ChatInput = {
        "application_id": application_id
    }
    if user_id is not None:
        input_["user_id"] = user_id
    if user_groups is not None:
        input_["user_groups"] = user_groups
    if conversation_id is not None:
        input_["conversation_id"] = conversation_id
    if parent_message_id is not None:
        input_["parent_message_id"] = parent_message_id
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if input_stream is not None:
        input_["input_stream"] = ensure_sync_iterator(input_stream)

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    try:
        yield response.output
    finally:
        response.response.close()