...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v3.0/luis/authoring/train.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v3.0/luis/authoring

     1  package authoring
     2  
     3  // Copyright (c) Microsoft Corporation. All rights reserved.
     4  // Licensed under the MIT License. See License.txt in the project root for license information.
     5  //
     6  // Code generated by Microsoft (R) AutoRest Code Generator.
     7  // Changes may cause incorrect behavior and will be lost if the code is regenerated.
     8  
     9  import (
    10  	"context"
    11  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"github.com/gofrs/uuid"
    15  	"net/http"
    16  )
    17  
    18  // TrainClient is the client for the Train methods of the Authoring service.
    19  type TrainClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewTrainClient creates an instance of the TrainClient client.
    24  func NewTrainClient(endpoint string) TrainClient {
    25  	return TrainClient{New(endpoint)}
    26  }
    27  
    28  // GetStatus gets the training status of all models (intents and entities) for the specified LUIS app. You must call
    29  // the train API to train the LUIS app before you call this API to get training status. "appID" specifies the LUIS app
    30  // ID. "versionId" specifies the version number of the LUIS app. For example, "0.1".
    31  // Parameters:
    32  // appID - the application ID.
    33  // versionID - the version ID.
    34  func (client TrainClient) GetStatus(ctx context.Context, appID uuid.UUID, versionID string) (result ListModelTrainingInfo, err error) {
    35  	if tracing.IsEnabled() {
    36  		ctx = tracing.StartSpan(ctx, fqdn+"/TrainClient.GetStatus")
    37  		defer func() {
    38  			sc := -1
    39  			if result.Response.Response != nil {
    40  				sc = result.Response.Response.StatusCode
    41  			}
    42  			tracing.EndSpan(ctx, sc, err)
    43  		}()
    44  	}
    45  	req, err := client.GetStatusPreparer(ctx, appID, versionID)
    46  	if err != nil {
    47  		err = autorest.NewErrorWithError(err, "authoring.TrainClient", "GetStatus", nil, "Failure preparing request")
    48  		return
    49  	}
    50  
    51  	resp, err := client.GetStatusSender(req)
    52  	if err != nil {
    53  		result.Response = autorest.Response{Response: resp}
    54  		err = autorest.NewErrorWithError(err, "authoring.TrainClient", "GetStatus", resp, "Failure sending request")
    55  		return
    56  	}
    57  
    58  	result, err = client.GetStatusResponder(resp)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "authoring.TrainClient", "GetStatus", resp, "Failure responding to request")
    61  		return
    62  	}
    63  
    64  	return
    65  }
    66  
    67  // GetStatusPreparer prepares the GetStatus request.
    68  func (client TrainClient) GetStatusPreparer(ctx context.Context, appID uuid.UUID, versionID string) (*http.Request, error) {
    69  	urlParameters := map[string]interface{}{
    70  		"Endpoint": client.Endpoint,
    71  	}
    72  
    73  	pathParameters := map[string]interface{}{
    74  		"appId":     autorest.Encode("path", appID),
    75  		"versionId": autorest.Encode("path", versionID),
    76  	}
    77  
    78  	preparer := autorest.CreatePreparer(
    79  		autorest.AsGet(),
    80  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
    81  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/train", pathParameters))
    82  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    83  }
    84  
    85  // GetStatusSender sends the GetStatus request. The method will close the
    86  // http.Response Body if it receives an error.
    87  func (client TrainClient) GetStatusSender(req *http.Request) (*http.Response, error) {
    88  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    89  }
    90  
    91  // GetStatusResponder handles the response to the GetStatus request. The method always
    92  // closes the http.Response Body.
    93  func (client TrainClient) GetStatusResponder(resp *http.Response) (result ListModelTrainingInfo, err error) {
    94  	err = autorest.Respond(
    95  		resp,
    96  		azure.WithErrorUnlessStatusCode(http.StatusOK),
    97  		autorest.ByUnmarshallingJSON(&result.Value),
    98  		autorest.ByClosing())
    99  	result.Response = autorest.Response{Response: resp}
   100  	return
   101  }
   102  
   103  // TrainVersion sends a training request for a version of a specified LUIS app. This POST request initiates a request
   104  // asynchronously. To determine whether the training request is successful, submit a GET request to get training
   105  // status. Note: The application version is not fully trained unless all the models (intents and entities) are trained
   106  // successfully or are up to date. To verify training success, get the training status at least once after training is
   107  // complete.
   108  // Parameters:
   109  // appID - the application ID.
   110  // versionID - the version ID.
   111  func (client TrainClient) TrainVersion(ctx context.Context, appID uuid.UUID, versionID string) (result EnqueueTrainingResponse, err error) {
   112  	if tracing.IsEnabled() {
   113  		ctx = tracing.StartSpan(ctx, fqdn+"/TrainClient.TrainVersion")
   114  		defer func() {
   115  			sc := -1
   116  			if result.Response.Response != nil {
   117  				sc = result.Response.Response.StatusCode
   118  			}
   119  			tracing.EndSpan(ctx, sc, err)
   120  		}()
   121  	}
   122  	req, err := client.TrainVersionPreparer(ctx, appID, versionID)
   123  	if err != nil {
   124  		err = autorest.NewErrorWithError(err, "authoring.TrainClient", "TrainVersion", nil, "Failure preparing request")
   125  		return
   126  	}
   127  
   128  	resp, err := client.TrainVersionSender(req)
   129  	if err != nil {
   130  		result.Response = autorest.Response{Response: resp}
   131  		err = autorest.NewErrorWithError(err, "authoring.TrainClient", "TrainVersion", resp, "Failure sending request")
   132  		return
   133  	}
   134  
   135  	result, err = client.TrainVersionResponder(resp)
   136  	if err != nil {
   137  		err = autorest.NewErrorWithError(err, "authoring.TrainClient", "TrainVersion", resp, "Failure responding to request")
   138  		return
   139  	}
   140  
   141  	return
   142  }
   143  
   144  // TrainVersionPreparer prepares the TrainVersion request.
   145  func (client TrainClient) TrainVersionPreparer(ctx context.Context, appID uuid.UUID, versionID string) (*http.Request, error) {
   146  	urlParameters := map[string]interface{}{
   147  		"Endpoint": client.Endpoint,
   148  	}
   149  
   150  	pathParameters := map[string]interface{}{
   151  		"appId":     autorest.Encode("path", appID),
   152  		"versionId": autorest.Encode("path", versionID),
   153  	}
   154  
   155  	preparer := autorest.CreatePreparer(
   156  		autorest.AsPost(),
   157  		autorest.WithCustomBaseURL("{Endpoint}/luis/authoring/v3.0-preview", urlParameters),
   158  		autorest.WithPathParameters("/apps/{appId}/versions/{versionId}/train", pathParameters))
   159  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   160  }
   161  
   162  // TrainVersionSender sends the TrainVersion request. The method will close the
   163  // http.Response Body if it receives an error.
   164  func (client TrainClient) TrainVersionSender(req *http.Request) (*http.Response, error) {
   165  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   166  }
   167  
   168  // TrainVersionResponder handles the response to the TrainVersion request. The method always
   169  // closes the http.Response Body.
   170  func (client TrainClient) TrainVersionResponder(resp *http.Response) (result EnqueueTrainingResponse, err error) {
   171  	err = autorest.Respond(
   172  		resp,
   173  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   174  		autorest.ByUnmarshallingJSON(&result),
   175  		autorest.ByClosing())
   176  	result.Response = autorest.Response{Response: resp}
   177  	return
   178  }
   179  

View as plain text