Skip to content

sample_training_session async

sample_training_session(
    training_session_name: TrainingSessionName,
    *,
    config_overrides: Optional[AsyncSageMakerTrainingSessionRuntimeClientConfig] = None,
    content_type: Optional[str] = None,
    accept: Optional[str] = None,
    model_package_arn: Optional[str] = None,
    body: Optional[InferenceBody] = None,
) -> SampleTrainingSessionOutput

Sends an inference request to the model associated with the specified training session and returns the response synchronously. The service passes the request and response bodies to and from the model without modification.

Parameters:

  • training_session_name (TrainingSessionName) –

    The name of the training session whose model to invoke.

  • content_type (Optional[str], default: None ) –

    The MIME type of the input data in the request body.

  • accept (Optional[str], default: None ) –

    The desired MIME type of the inference body in the response.

  • model_package_arn (Optional[str], default: None ) –

    The ARN of the model package whose checkpoint to invoke.

  • body (Optional[InferenceBody], default: None ) –

    The raw inference request body.

Raises:

  • ConflictException –

    The training session is in a state that cannot accept new operations. The session must be in Running or Blocked state to accept requests.

  • InternalServerException –

    An internal service error occurred. Retry the request using exponential backoff.

  • ResourceNotFoundException –

    The specified training session or operation does not exist, or the operation does not belong to the specified training session.

  • ThrottlingException –

    The request was throttled. Retry the request after a brief wait using exponential backoff.

  • ValidationException –

    The request is not valid. Check the request syntax and parameters. Examples include invalid sequence numbers, malformed client tokens, missing required fields, or invalid operation configuration.

  • UnknownServiceError –

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

Examples:

Sample from a training session Sends a chat completion request to the session's current weights and receives the complete response in a single payload.

>>> await client.sample_training_session(training_session_name='my-training-session', content_type='application/json', accept='application/json', body='eyJtZXNzYWdlcyI6W3sicm9sZSI6InVzZXIiLCJjb250ZW50IjoiV2hhdCBpcyB0aGUgY2FwaXRhbCBvZiBGcmFuY2U/In1dLCJtYXhfdG9rZW5zIjoxMjh9')
Source code in docs_src/capo_sagemakertrainingsessionruntime/_services/async_sage_maker_training_session_runtime.py
async def sample_training_session(
    self,
    training_session_name: "capo_sagemakertrainingsessionruntime.types.training_session_name.TrainingSessionName",
    *,
    config_overrides: Optional[
        AsyncSageMakerTrainingSessionRuntimeClientConfig
    ] = None,
    content_type: Optional[str] = None,
    accept: Optional[str] = None,
    model_package_arn: Optional[str] = None,
    body: Optional[
        "capo_sagemakertrainingsessionruntime.types.inference_body.InferenceBody"
    ] = None,
) -> "capo_sagemakertrainingsessionruntime.types.sample_training_session_output.SampleTrainingSessionOutput":
    """<p>Sends an inference request to the model associated with the specified training session and returns the response synchronously. The service passes the request and response bodies to and from the model without modification.</p>

    Args:
        training_session_name: <p>The name of the training session whose model to invoke.</p>
        content_type: <p>The MIME type of the input data in the request body.</p>
        accept: <p>The desired MIME type of the inference body in the response.</p>
        model_package_arn: <p>The ARN of the model package whose checkpoint to invoke.</p>
        body: <p>The raw inference request body.</p>

    Raises:
        capo_sagemakertrainingsessionruntime.errors.conflict_exception.ConflictException: <p>The training session is in a state that cannot accept new operations. The session must be in <code>Running</code> or <code>Blocked</code> state to accept requests.</p>
        capo_sagemakertrainingsessionruntime.errors.internal_server_exception.InternalServerException: <p>An internal service error occurred. Retry the request using exponential backoff.</p>
        capo_sagemakertrainingsessionruntime.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified training session or operation does not exist, or the operation does not belong to the specified training session.</p>
        capo_sagemakertrainingsessionruntime.errors.throttling_exception.ThrottlingException: <p>The request was throttled. Retry the request after a brief wait using exponential backoff.</p>
        capo_sagemakertrainingsessionruntime.errors.validation_exception.ValidationException: <p>The request is not valid. Check the request syntax and parameters. Examples include invalid sequence numbers, malformed client tokens, missing required fields, or invalid operation configuration.</p>
        capo_sagemakertrainingsessionruntime.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Sample from a training session
        Sends a chat completion request to the session's current weights and receives the complete response in a single payload.

        >>> await client.sample_training_session(training_session_name='my-training-session', content_type='application/json', accept='application/json', body='eyJtZXNzYWdlcyI6W3sicm9sZSI6InVzZXIiLCJjb250ZW50IjoiV2hhdCBpcyB0aGUgY2FwaXRhbCBvZiBGcmFuY2U/In1dLCJtYXhfdG9rZW5zIjoxMjh9')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_sagemakertrainingsessionruntime.types.sample_training_session_input.SampleTrainingSessionInput]",
    ) -> AsyncOperationResponse[
        "capo_sagemakertrainingsessionruntime.types.sample_training_session_output.SampleTrainingSessionOutput"
    ]:
        import capo_sagemakertrainingsessionruntime._operations.lego_router_service.sample_training_session

        (
            output,
            http_response,
        ) = await capo_sagemakertrainingsessionruntime._operations.lego_router_service.sample_training_session.async_sample_training_session(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_sagemakertrainingsessionruntime.types.sample_training_session_input.SampleTrainingSessionInput",
    ) -> dict[str, Any]:
        import capo_sagemakertrainingsessionruntime.types.sample_training_session_input

        return capo_sagemakertrainingsessionruntime.types.sample_training_session_input.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_sagemakertrainingsessionruntime.types.sample_training_session_output.SampleTrainingSessionOutput",
    ) -> dict[str, Any]:
        import capo_sagemakertrainingsessionruntime.types.sample_training_session_output

        return capo_sagemakertrainingsessionruntime.types.sample_training_session_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "SampleTrainingSession",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_sagemakertrainingsessionruntime.types.sample_training_session_input.SampleTrainingSessionInput = {
        "training_session_name": training_session_name
    }
    if content_type is not None:
        input_["content_type"] = content_type
    if accept is not None:
        input_["accept"] = accept
    if model_package_arn is not None:
        input_["model_package_arn"] = model_package_arn
    if body is not None:
        input_["body"] = body

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output