requestPrompt method

Future<PromptResponse> requestPrompt(
  1. Map<String, String>? templateVariables
)

Requests an AI prompt. The prompt is returned as a single response.

Param templateVariables is a map of template variables to use for the prompt request. throws MissingPromptVariableException if a template variable is missing. throws an APIGatewayException if the API gateway returns an error.

Implementation

Future<PromptResponse> requestPrompt(
  Map<String, String>? templateVariables,
) async {
  if (_isDebug) {
    _logger.fine("requesting prompt");
  }

  try {
    return await _stub.requestPrompt(
      _createPromptRequest(templateVariables),
      options: CallOptions(metadata: {
        "authorization": "Bearer $_apiToken",
      }),
    );
  } on GrpcError catch (e) {
    if (_isDebug) {
      _logger.fine("exception requesting prompt: $e");
    }
    if (e.code == StatusCode.invalidArgument) {
      throw MissingPromptVariableException(
          e.message ?? _missingTemplateVariableMessage);
    }
    throw APIGatewayException(e.message ?? _apiGatewayErrorMessage);
  }
}