makeTemplateRequest<T> method

Future<T> makeTemplateRequest<T>(
  1. TemplateTask task,
  2. String templateId,
  3. Map<String, Object?>? inputs,
  4. Iterable<Content>? history,
  5. List<TemplateTool>? tools,
  6. TemplateToolConfig? toolConfig,
  7. T parse(
    1. Map<String, Object?>
    ),
)
inherited

Makes a unary request to a template-based API.

This method sends a request to the API with the given task, templateId, and inputs. It returns a Future that completes with the parsed response.

Implementation

Future<T> makeTemplateRequest<T>(
    TemplateTask task,
    String templateId,
    Map<String, Object?>? inputs,
    Iterable<Content>? history,
    List<TemplateTool>? tools,
    TemplateToolConfig? toolConfig,
    T Function(Map<String, Object?>) parse) {
  Map<String, Object?> body = {};
  if (inputs != null) {
    body['inputs'] = _serializeTemplateInputs(inputs);
  }
  if (history != null) {
    body['history'] = history.map((c) => c.toJson()).toList();
  }
  if (tools != null) {
    body['tools'] = tools.map((t) => t.toJson()).toList();
  }
  if (toolConfig != null) {
    body['toolConfig'] = toolConfig.toJson();
  }
  return _client
      .makeRequest(templateTaskUri(task, templateId), body)
      .then(parse);
}