construct2 function

int construct2(
  1. String apiKey,
  2. String modelId,
  3. String? baseUrl,
  4. Pointer<Void> plain(
    1. Pointer<Utf8>,
    2. Pointer<Utf8>,
    3. Pointer<Uint64>
    ),
  5. Pointer<Void> withBase(
    1. Pointer<Utf8>,
    2. Pointer<Utf8>,
    3. Pointer<Utf8>,
    4. Pointer<Uint64>,
    ),
)

Shared constructor for (api_key, model_id[, base_url], out_handle) providers.

Implementation

int construct2(
  String apiKey,
  String modelId,
  String? baseUrl,
  Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint64>) plain,
  Pointer<Void> Function(
          Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint64>)
      withBase,
) {
  return withUtf8(apiKey, (keyPtr) {
    return withUtf8(modelId, (idPtr) {
      if (baseUrl == null) {
        return takeHandle((out) => plain(keyPtr, idPtr, out), 'new');
      }
      return withUtf8(baseUrl, (basePtr) {
        return takeHandle(
            (out) => withBase(keyPtr, idPtr, basePtr, out), 'new_with_base');
      });
    });
  });
}