/// <summary>
        /// Creates a composed model from a collection of existing trained models with labels.
        /// </summary>
        /// <param name="modelIds">List of model ids to use in the composed model.</param>
        /// <param name="createComposedModelOptions">A set of options available for configuring the create composed model request.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <returns>
        /// <para>A <see cref="CreateComposedModelOperation"/> to wait on this long-running operation. Its Value upon successful
        /// completion will contain meta-data about the composed model.</para>
        /// </returns>
        public virtual async Task <CreateComposedModelOperation> StartCreateComposedModelAsync(IEnumerable <string> modelIds, CreateComposedModelOptions createComposedModelOptions = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(modelIds, nameof(modelIds));
            createComposedModelOptions ??= new CreateComposedModelOptions();

            using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormTrainingClient)}.{nameof(StartCreateComposedModel)}");
            scope.Start();

            try
            {
                var modelIdsGuid = new List <Guid>();
                foreach (var modelId in modelIds)
                {
                    modelIdsGuid.Add(ClientCommon.ValidateModelId(modelId, nameof(modelId)));
                }

                var composeRequest = new ComposeRequest(modelIdsGuid);
                if (createComposedModelOptions.ModelName?.Length > 0)
                {
                    composeRequest.ModelName = createComposedModelOptions.ModelName;
                }

                ResponseWithHeaders <FormRecognizerComposeCustomModelsAsyncHeaders> response = await ServiceClient.ComposeCustomModelsAsyncAsync(composeRequest).ConfigureAwait(false);

                return(new CreateComposedModelOperation(response.Headers.Location, ServiceClient, Diagnostics));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a composed model from a collection of existing models trained with labels.
        /// </summary>
        /// <param name="modelIds">List of model ids to use in the composed model.</param>
        /// <param name="modelName">An optional, user-defined name to associate with the model.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
        /// <remarks>
        /// Method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and up.
        /// </remarks>
        /// <returns>
        /// <para>A <see cref="CreateComposedModelOperation"/> to wait on this long-running operation. Its Value upon successful
        /// completion will contain meta-data about the composed model.</para>
        /// </returns>
        public virtual CreateComposedModelOperation StartCreateComposedModel(IEnumerable <string> modelIds, string modelName = default, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(modelIds, nameof(modelIds));

            using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormTrainingClient)}.{nameof(StartCreateComposedModel)}");
            scope.Start();

            try
            {
                var modelIdsGuid = new List <Guid>();
                foreach (var modelId in modelIds)
                {
                    modelIdsGuid.Add(ClientCommon.ValidateModelId(modelId, nameof(modelId)));
                }

                var composeRequest = new ComposeRequest(modelIdsGuid);
                composeRequest.ModelName = modelName;

                ResponseWithHeaders <FormRecognizerComposeCustomModelsAsyncHeaders> response = ServiceClient.ComposeCustomModelsAsync(composeRequest, cancellationToken);
                return(new CreateComposedModelOperation(response.Headers.Location, ServiceClient, Diagnostics, ServiceVersion));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Concatenates a list of existing objects into a new object in the same bucket.
        /// Documentation https://developers.google.com/storage/v1beta2/reference/objects/compose
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Storage service.</param>
        /// <param name="destinationBucket">Name of the bucket in which to store the new object.</param>
        /// <param name="destinationObject">Name of the new object.</param>
        /// <param name="body">A valid Storage v1beta2 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>ObjectResponse</returns>
        public static Object Compose(StorageService service, string destinationBucket, string destinationObject, ComposeRequest body, ObjectsComposeOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (destinationBucket == null)
                {
                    throw new ArgumentNullException(destinationBucket);
                }
                if (destinationObject == null)
                {
                    throw new ArgumentNullException(destinationObject);
                }

                // Building the initial request.
                var request = service.Objects.Compose(body, destinationBucket, destinationObject);

                // Applying optional parameters to the request.
                request = (ObjectsResource.ComposeRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Objects.Compose failed.", ex);
            }
        }
Exemplo n.º 4
0
 public Task ComposeAsync(ComposeRequest request, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(PostAsync(UrlConstants.ComposeUrl, request, cancellationToken));
 }