diff --git a/profiles/preview/cognitiveservices/qnamaker/models.go b/profiles/preview/cognitiveservices/qnamaker/models.go new file mode 100644 index 000000000000..43785253c46b --- /dev/null +++ b/profiles/preview/cognitiveservices/qnamaker/models.go @@ -0,0 +1,135 @@ +// +build go1.9 + +// Copyright 2018 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This code was auto-generated by: +// github.com/Azure/azure-sdk-for-go/tools/profileBuilder + +package qnamaker + +import original "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v4.0/qnamaker" + +type AlterationsClient = original.AlterationsClient +type BaseClient = original.BaseClient +type EndpointClient = original.EndpointClient +type KnowledgebaseClient = original.KnowledgebaseClient +type EnvironmentType = original.EnvironmentType + +const ( + Prod EnvironmentType = original.Prod + Test EnvironmentType = original.Test +) + +type ErrorCodeType = original.ErrorCodeType + +const ( + BadArgument ErrorCodeType = original.BadArgument + EndpointKeysError ErrorCodeType = original.EndpointKeysError + ExtractionFailure ErrorCodeType = original.ExtractionFailure + Forbidden ErrorCodeType = original.Forbidden + KbNotFound ErrorCodeType = original.KbNotFound + NotFound ErrorCodeType = original.NotFound + OperationNotFound ErrorCodeType = original.OperationNotFound + QnaRuntimeError ErrorCodeType = original.QnaRuntimeError + QuotaExceeded ErrorCodeType = original.QuotaExceeded + ServiceError ErrorCodeType = original.ServiceError + SKULimitExceeded ErrorCodeType = original.SKULimitExceeded + Unauthorized ErrorCodeType = original.Unauthorized + Unspecified ErrorCodeType = original.Unspecified + ValidationFailure ErrorCodeType = original.ValidationFailure +) + +type KnowledgebaseEnvironmentType = original.KnowledgebaseEnvironmentType + +const ( + KnowledgebaseEnvironmentTypeProd KnowledgebaseEnvironmentType = original.KnowledgebaseEnvironmentTypeProd + KnowledgebaseEnvironmentTypeTest KnowledgebaseEnvironmentType = original.KnowledgebaseEnvironmentTypeTest +) + +type OperationStateType = original.OperationStateType + +const ( + Failed OperationStateType = original.Failed + NotStarted OperationStateType = original.NotStarted + Running OperationStateType = original.Running + Succeeded OperationStateType = original.Succeeded +) + +type AlterationsDTO = original.AlterationsDTO +type CreateKbDTO = original.CreateKbDTO +type CreateKbInputDTO = original.CreateKbInputDTO +type DeleteKbContentsDTO = original.DeleteKbContentsDTO +type EndpointKeysDTO = original.EndpointKeysDTO +type Error = original.Error +type ErrorResponse = original.ErrorResponse +type ErrorResponseError = original.ErrorResponseError +type FileDTO = original.FileDTO +type InnerErrorModel = original.InnerErrorModel +type KnowledgebaseDTO = original.KnowledgebaseDTO +type KnowledgebasesDTO = original.KnowledgebasesDTO +type MetadataDTO = original.MetadataDTO +type Operation = original.Operation +type QnADocumentsDTO = original.QnADocumentsDTO +type QnADTO = original.QnADTO +type ReplaceKbDTO = original.ReplaceKbDTO +type UpdateKbContentsDTO = original.UpdateKbContentsDTO +type UpdateKbOperationDTO = original.UpdateKbOperationDTO +type UpdateKbOperationDTOAdd = original.UpdateKbOperationDTOAdd +type UpdateKbOperationDTODelete = original.UpdateKbOperationDTODelete +type UpdateKbOperationDTOUpdate = original.UpdateKbOperationDTOUpdate +type UpdateMetadataDTO = original.UpdateMetadataDTO +type UpdateQnaDTO = original.UpdateQnaDTO +type UpdateQnaDTOMetadata = original.UpdateQnaDTOMetadata +type UpdateQnaDTOQuestions = original.UpdateQnaDTOQuestions +type UpdateQuestionsDTO = original.UpdateQuestionsDTO +type WordAlterationsDTO = original.WordAlterationsDTO +type OperationsClient = original.OperationsClient + +func NewAlterationsClient(endpoint string) AlterationsClient { + return original.NewAlterationsClient(endpoint) +} +func New(endpoint string) BaseClient { + return original.New(endpoint) +} +func NewWithoutDefaults(endpoint string) BaseClient { + return original.NewWithoutDefaults(endpoint) +} +func NewEndpointClient(endpoint string) EndpointClient { + return original.NewEndpointClient(endpoint) +} +func NewKnowledgebaseClient(endpoint string) KnowledgebaseClient { + return original.NewKnowledgebaseClient(endpoint) +} +func PossibleEnvironmentTypeValues() []EnvironmentType { + return original.PossibleEnvironmentTypeValues() +} +func PossibleErrorCodeTypeValues() []ErrorCodeType { + return original.PossibleErrorCodeTypeValues() +} +func PossibleKnowledgebaseEnvironmentTypeValues() []KnowledgebaseEnvironmentType { + return original.PossibleKnowledgebaseEnvironmentTypeValues() +} +func PossibleOperationStateTypeValues() []OperationStateType { + return original.PossibleOperationStateTypeValues() +} +func NewOperationsClient(endpoint string) OperationsClient { + return original.NewOperationsClient(endpoint) +} +func UserAgent() string { + return original.UserAgent() + " profiles/preview" +} +func Version() string { + return original.Version() +} diff --git a/profiles/preview/cognitiveservices/qnamaker/qnamakerapi/models.go b/profiles/preview/cognitiveservices/qnamaker/qnamakerapi/models.go new file mode 100644 index 000000000000..0414605643d7 --- /dev/null +++ b/profiles/preview/cognitiveservices/qnamaker/qnamakerapi/models.go @@ -0,0 +1,27 @@ +// +build go1.9 + +// Copyright 2018 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This code was auto-generated by: +// github.com/Azure/azure-sdk-for-go/tools/profileBuilder + +package qnamakerapi + +import original "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v4.0/qnamaker/qnamakerapi" + +type EndpointClientAPI = original.EndpointClientAPI +type AlterationsClientAPI = original.AlterationsClientAPI +type KnowledgebaseClientAPI = original.KnowledgebaseClientAPI +type OperationsClientAPI = original.OperationsClientAPI diff --git a/services/cognitiveservices/v4.0/qnamaker/alterations.go b/services/cognitiveservices/v4.0/qnamaker/alterations.go new file mode 100644 index 000000000000..bfd6df3ce5c0 --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/alterations.go @@ -0,0 +1,178 @@ +package qnamaker + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// AlterationsClient is the an API for QnAMaker Service +type AlterationsClient struct { + BaseClient +} + +// NewAlterationsClient creates an instance of the AlterationsClient client. +func NewAlterationsClient(endpoint string) AlterationsClient { + return AlterationsClient{New(endpoint)} +} + +// Get sends the get request. +func (client AlterationsClient) Get(ctx context.Context) (result WordAlterationsDTO, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AlterationsClient.Get") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client AlterationsClient) GetPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPath("/alterations")) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client AlterationsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client AlterationsClient) GetResponder(resp *http.Response) (result WordAlterationsDTO, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Replace sends the replace request. +// Parameters: +// wordAlterations - new alterations data. +func (client AlterationsClient) Replace(ctx context.Context, wordAlterations WordAlterationsDTO) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/AlterationsClient.Replace") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: wordAlterations, + Constraints: []validation.Constraint{{Target: "wordAlterations.WordAlterations", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("qnamaker.AlterationsClient", "Replace", err.Error()) + } + + req, err := client.ReplacePreparer(ctx, wordAlterations) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Replace", nil, "Failure preparing request") + return + } + + resp, err := client.ReplaceSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Replace", resp, "Failure sending request") + return + } + + result, err = client.ReplaceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.AlterationsClient", "Replace", resp, "Failure responding to request") + } + + return +} + +// ReplacePreparer prepares the Replace request. +func (client AlterationsClient) ReplacePreparer(ctx context.Context, wordAlterations WordAlterationsDTO) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPath("/alterations"), + autorest.WithJSON(wordAlterations)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ReplaceSender sends the Replace request. The method will close the +// http.Response Body if it receives an error. +func (client AlterationsClient) ReplaceSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ReplaceResponder handles the response to the Replace request. The method always +// closes the http.Response Body. +func (client AlterationsClient) ReplaceResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} diff --git a/services/cognitiveservices/v4.0/qnamaker/client.go b/services/cognitiveservices/v4.0/qnamaker/client.go new file mode 100644 index 000000000000..7794a7e42fdc --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/client.go @@ -0,0 +1,44 @@ +// Package qnamaker implements the Azure ARM Qnamaker service API version 4.0. +// +// An API for QnAMaker Service +package qnamaker + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +// BaseClient is the base client for Qnamaker. +type BaseClient struct { + autorest.Client + Endpoint string +} + +// New creates an instance of the BaseClient client. +func New(endpoint string) BaseClient { + return NewWithoutDefaults(endpoint) +} + +// NewWithoutDefaults creates an instance of the BaseClient client. +func NewWithoutDefaults(endpoint string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + Endpoint: endpoint, + } +} diff --git a/services/cognitiveservices/v4.0/qnamaker/endpoint.go b/services/cognitiveservices/v4.0/qnamaker/endpoint.go new file mode 100644 index 000000000000..39cecbfd9bdb --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/endpoint.go @@ -0,0 +1,174 @@ +package qnamaker + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// EndpointClient is the an API for QnAMaker Service +type EndpointClient struct { + BaseClient +} + +// NewEndpointClient creates an instance of the EndpointClient client. +func NewEndpointClient(endpoint string) EndpointClient { + return EndpointClient{New(endpoint)} +} + +// GetKeys sends the get keys request. +func (client EndpointClient) GetKeys(ctx context.Context) (result EndpointKeysDTO, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EndpointClient.GetKeys") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetKeysPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.EndpointClient", "GetKeys", nil, "Failure preparing request") + return + } + + resp, err := client.GetKeysSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.EndpointClient", "GetKeys", resp, "Failure sending request") + return + } + + result, err = client.GetKeysResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.EndpointClient", "GetKeys", resp, "Failure responding to request") + } + + return +} + +// GetKeysPreparer prepares the GetKeys request. +func (client EndpointClient) GetKeysPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPath("/endpointkeys")) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetKeysSender sends the GetKeys request. The method will close the +// http.Response Body if it receives an error. +func (client EndpointClient) GetKeysSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetKeysResponder handles the response to the GetKeys request. The method always +// closes the http.Response Body. +func (client EndpointClient) GetKeysResponder(resp *http.Response) (result EndpointKeysDTO, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// RefreshKeys sends the refresh keys request. +// Parameters: +// keyType - type of Key +func (client EndpointClient) RefreshKeys(ctx context.Context, keyType string) (result EndpointKeysDTO, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/EndpointClient.RefreshKeys") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.RefreshKeysPreparer(ctx, keyType) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.EndpointClient", "RefreshKeys", nil, "Failure preparing request") + return + } + + resp, err := client.RefreshKeysSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.EndpointClient", "RefreshKeys", resp, "Failure sending request") + return + } + + result, err = client.RefreshKeysResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.EndpointClient", "RefreshKeys", resp, "Failure responding to request") + } + + return +} + +// RefreshKeysPreparer prepares the RefreshKeys request. +func (client EndpointClient) RefreshKeysPreparer(ctx context.Context, keyType string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "keyType": autorest.Encode("path", keyType), + } + + preparer := autorest.CreatePreparer( + autorest.AsPatch(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/endpointkeys/{keyType}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// RefreshKeysSender sends the RefreshKeys request. The method will close the +// http.Response Body if it receives an error. +func (client EndpointClient) RefreshKeysSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// RefreshKeysResponder handles the response to the RefreshKeys request. The method always +// closes the http.Response Body. +func (client EndpointClient) RefreshKeysResponder(resp *http.Response) (result EndpointKeysDTO, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/cognitiveservices/v4.0/qnamaker/knowledgebase.go b/services/cognitiveservices/v4.0/qnamaker/knowledgebase.go new file mode 100644 index 000000000000..9dec1b75d791 --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/knowledgebase.go @@ -0,0 +1,625 @@ +package qnamaker + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// KnowledgebaseClient is the an API for QnAMaker Service +type KnowledgebaseClient struct { + BaseClient +} + +// NewKnowledgebaseClient creates an instance of the KnowledgebaseClient client. +func NewKnowledgebaseClient(endpoint string) KnowledgebaseClient { + return KnowledgebaseClient{New(endpoint)} +} + +// Create sends the create request. +// Parameters: +// createKbPayload - post body of the request. +func (client KnowledgebaseClient) Create(ctx context.Context, createKbPayload CreateKbDTO) (result Operation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.Create") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: createKbPayload, + Constraints: []validation.Constraint{{Target: "createKbPayload.Name", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "createKbPayload.Name", Name: validation.MaxLength, Rule: 100, Chain: nil}, + {Target: "createKbPayload.Name", Name: validation.MinLength, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("qnamaker.KnowledgebaseClient", "Create", err.Error()) + } + + req, err := client.CreatePreparer(ctx, createKbPayload) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Create", nil, "Failure preparing request") + return + } + + resp, err := client.CreateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Create", resp, "Failure sending request") + return + } + + result, err = client.CreateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Create", resp, "Failure responding to request") + } + + return +} + +// CreatePreparer prepares the Create request. +func (client KnowledgebaseClient) CreatePreparer(ctx context.Context, createKbPayload CreateKbDTO) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPath("/knowledgebases/create"), + autorest.WithJSON(createKbPayload)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateSender sends the Create request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) CreateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// CreateResponder handles the response to the Create request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) CreateResponder(resp *http.Response) (result Operation, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete sends the delete request. +// Parameters: +// kbID - knowledgebase id. +func (client KnowledgebaseClient) Delete(ctx context.Context, kbID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.Delete") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DeletePreparer(ctx, kbID) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client KnowledgebaseClient) DeletePreparer(ctx context.Context, kbID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "kbId": autorest.Encode("path", kbID), + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/knowledgebases/{kbId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Download sends the download request. +// Parameters: +// kbID - knowledgebase id. +// environment - specifies whether environment is Test or Prod. +func (client KnowledgebaseClient) Download(ctx context.Context, kbID string, environment EnvironmentType) (result QnADocumentsDTO, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.Download") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.DownloadPreparer(ctx, kbID, environment) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Download", nil, "Failure preparing request") + return + } + + resp, err := client.DownloadSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Download", resp, "Failure sending request") + return + } + + result, err = client.DownloadResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Download", resp, "Failure responding to request") + } + + return +} + +// DownloadPreparer prepares the Download request. +func (client KnowledgebaseClient) DownloadPreparer(ctx context.Context, kbID string, environment EnvironmentType) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "environment": autorest.Encode("path", environment), + "kbId": autorest.Encode("path", kbID), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/knowledgebases/{kbId}/{environment}/qna", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DownloadSender sends the Download request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) DownloadSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// DownloadResponder handles the response to the Download request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) DownloadResponder(resp *http.Response) (result QnADocumentsDTO, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetDetails sends the get details request. +// Parameters: +// kbID - knowledgebase id. +func (client KnowledgebaseClient) GetDetails(ctx context.Context, kbID string) (result KnowledgebaseDTO, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.GetDetails") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetDetailsPreparer(ctx, kbID) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "GetDetails", nil, "Failure preparing request") + return + } + + resp, err := client.GetDetailsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "GetDetails", resp, "Failure sending request") + return + } + + result, err = client.GetDetailsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "GetDetails", resp, "Failure responding to request") + } + + return +} + +// GetDetailsPreparer prepares the GetDetails request. +func (client KnowledgebaseClient) GetDetailsPreparer(ctx context.Context, kbID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "kbId": autorest.Encode("path", kbID), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/knowledgebases/{kbId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetDetailsSender sends the GetDetails request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) GetDetailsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetDetailsResponder handles the response to the GetDetails request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) GetDetailsResponder(resp *http.Response) (result KnowledgebaseDTO, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// ListAll sends the list all request. +func (client KnowledgebaseClient) ListAll(ctx context.Context) (result KnowledgebasesDTO, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.ListAll") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.ListAllPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "ListAll", nil, "Failure preparing request") + return + } + + resp, err := client.ListAllSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "ListAll", resp, "Failure sending request") + return + } + + result, err = client.ListAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "ListAll", resp, "Failure responding to request") + } + + return +} + +// ListAllPreparer prepares the ListAll request. +func (client KnowledgebaseClient) ListAllPreparer(ctx context.Context) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPath("/knowledgebases")) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListAllSender sends the ListAll request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) ListAllSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListAllResponder handles the response to the ListAll request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) ListAllResponder(resp *http.Response) (result KnowledgebasesDTO, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Publish sends the publish request. +// Parameters: +// kbID - knowledgebase id. +func (client KnowledgebaseClient) Publish(ctx context.Context, kbID string) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.Publish") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.PublishPreparer(ctx, kbID) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Publish", nil, "Failure preparing request") + return + } + + resp, err := client.PublishSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Publish", resp, "Failure sending request") + return + } + + result, err = client.PublishResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Publish", resp, "Failure responding to request") + } + + return +} + +// PublishPreparer prepares the Publish request. +func (client KnowledgebaseClient) PublishPreparer(ctx context.Context, kbID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "kbId": autorest.Encode("path", kbID), + } + + preparer := autorest.CreatePreparer( + autorest.AsPost(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/knowledgebases/{kbId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// PublishSender sends the Publish request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) PublishSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// PublishResponder handles the response to the Publish request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) PublishResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Replace sends the replace request. +// Parameters: +// kbID - knowledgebase id. +// replaceKb - an instance of ReplaceKbDTO which contains list of qnas to be uploaded +func (client KnowledgebaseClient) Replace(ctx context.Context, kbID string, replaceKb ReplaceKbDTO) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.Replace") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: replaceKb, + Constraints: []validation.Constraint{{Target: "replaceKb.QnAList", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("qnamaker.KnowledgebaseClient", "Replace", err.Error()) + } + + req, err := client.ReplacePreparer(ctx, kbID, replaceKb) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Replace", nil, "Failure preparing request") + return + } + + resp, err := client.ReplaceSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Replace", resp, "Failure sending request") + return + } + + result, err = client.ReplaceResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Replace", resp, "Failure responding to request") + } + + return +} + +// ReplacePreparer prepares the Replace request. +func (client KnowledgebaseClient) ReplacePreparer(ctx context.Context, kbID string, replaceKb ReplaceKbDTO) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "kbId": autorest.Encode("path", kbID), + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/knowledgebases/{kbId}", pathParameters), + autorest.WithJSON(replaceKb)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ReplaceSender sends the Replace request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) ReplaceSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ReplaceResponder handles the response to the Replace request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) ReplaceResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent), + autorest.ByClosing()) + result.Response = resp + return +} + +// Update sends the update request. +// Parameters: +// kbID - knowledgebase id. +// updateKb - post body of the request. +func (client KnowledgebaseClient) Update(ctx context.Context, kbID string, updateKb UpdateKbOperationDTO) (result Operation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/KnowledgebaseClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.UpdatePreparer(ctx, kbID, updateKb) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.KnowledgebaseClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client KnowledgebaseClient) UpdatePreparer(ctx context.Context, kbID string, updateKb UpdateKbOperationDTO) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "kbId": autorest.Encode("path", kbID), + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/knowledgebases/{kbId}", pathParameters), + autorest.WithJSON(updateKb)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client KnowledgebaseClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client KnowledgebaseClient) UpdateResponder(resp *http.Response) (result Operation, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/cognitiveservices/v4.0/qnamaker/models.go b/services/cognitiveservices/v4.0/qnamaker/models.go new file mode 100644 index 000000000000..d5c7c73750ed --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/models.go @@ -0,0 +1,402 @@ +package qnamaker + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +// The package's fully qualified name. +const fqdn = "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v4.0/qnamaker" + +// EnvironmentType enumerates the values for environment type. +type EnvironmentType string + +const ( + // Prod ... + Prod EnvironmentType = "Prod" + // Test ... + Test EnvironmentType = "Test" +) + +// PossibleEnvironmentTypeValues returns an array of possible values for the EnvironmentType const type. +func PossibleEnvironmentTypeValues() []EnvironmentType { + return []EnvironmentType{Prod, Test} +} + +// ErrorCodeType enumerates the values for error code type. +type ErrorCodeType string + +const ( + // BadArgument ... + BadArgument ErrorCodeType = "BadArgument" + // EndpointKeysError ... + EndpointKeysError ErrorCodeType = "EndpointKeysError" + // ExtractionFailure ... + ExtractionFailure ErrorCodeType = "ExtractionFailure" + // Forbidden ... + Forbidden ErrorCodeType = "Forbidden" + // KbNotFound ... + KbNotFound ErrorCodeType = "KbNotFound" + // NotFound ... + NotFound ErrorCodeType = "NotFound" + // OperationNotFound ... + OperationNotFound ErrorCodeType = "OperationNotFound" + // QnaRuntimeError ... + QnaRuntimeError ErrorCodeType = "QnaRuntimeError" + // QuotaExceeded ... + QuotaExceeded ErrorCodeType = "QuotaExceeded" + // ServiceError ... + ServiceError ErrorCodeType = "ServiceError" + // SKULimitExceeded ... + SKULimitExceeded ErrorCodeType = "SKULimitExceeded" + // Unauthorized ... + Unauthorized ErrorCodeType = "Unauthorized" + // Unspecified ... + Unspecified ErrorCodeType = "Unspecified" + // ValidationFailure ... + ValidationFailure ErrorCodeType = "ValidationFailure" +) + +// PossibleErrorCodeTypeValues returns an array of possible values for the ErrorCodeType const type. +func PossibleErrorCodeTypeValues() []ErrorCodeType { + return []ErrorCodeType{BadArgument, EndpointKeysError, ExtractionFailure, Forbidden, KbNotFound, NotFound, OperationNotFound, QnaRuntimeError, QuotaExceeded, ServiceError, SKULimitExceeded, Unauthorized, Unspecified, ValidationFailure} +} + +// KnowledgebaseEnvironmentType enumerates the values for knowledgebase environment type. +type KnowledgebaseEnvironmentType string + +const ( + // KnowledgebaseEnvironmentTypeProd ... + KnowledgebaseEnvironmentTypeProd KnowledgebaseEnvironmentType = "Prod" + // KnowledgebaseEnvironmentTypeTest ... + KnowledgebaseEnvironmentTypeTest KnowledgebaseEnvironmentType = "Test" +) + +// PossibleKnowledgebaseEnvironmentTypeValues returns an array of possible values for the KnowledgebaseEnvironmentType const type. +func PossibleKnowledgebaseEnvironmentTypeValues() []KnowledgebaseEnvironmentType { + return []KnowledgebaseEnvironmentType{KnowledgebaseEnvironmentTypeProd, KnowledgebaseEnvironmentTypeTest} +} + +// OperationStateType enumerates the values for operation state type. +type OperationStateType string + +const ( + // Failed ... + Failed OperationStateType = "Failed" + // NotStarted ... + NotStarted OperationStateType = "NotStarted" + // Running ... + Running OperationStateType = "Running" + // Succeeded ... + Succeeded OperationStateType = "Succeeded" +) + +// PossibleOperationStateTypeValues returns an array of possible values for the OperationStateType const type. +func PossibleOperationStateTypeValues() []OperationStateType { + return []OperationStateType{Failed, NotStarted, Running, Succeeded} +} + +// AlterationsDTO collection of words that are synonyms. +type AlterationsDTO struct { + // Alterations - Words that are synonymous with each other. + Alterations *[]string `json:"alterations,omitempty"` +} + +// CreateKbDTO post body schema for CreateKb operation. +type CreateKbDTO struct { + // Name - Friendly name for the knowledgebase. + Name *string `json:"name,omitempty"` + // QnaList - List of Q-A (QnADTO) to be added to the knowledgebase. Q-A Ids are assigned by the service and should be omitted. + QnaList *[]QnADTO `json:"qnaList,omitempty"` + // Urls - List of URLs to be used for extracting Q-A. + Urls *[]string `json:"urls,omitempty"` + // Files - List of files from which to Extract Q-A. + Files *[]FileDTO `json:"files,omitempty"` +} + +// CreateKbInputDTO input to create KB. +type CreateKbInputDTO struct { + // QnaList - List of QNA to be added to the index. Ids are generated by the service and should be omitted. + QnaList *[]QnADTO `json:"qnaList,omitempty"` + // Urls - List of URLs to be added to knowledgebase. + Urls *[]string `json:"urls,omitempty"` + // Files - List of files to be added to knowledgebase. + Files *[]FileDTO `json:"files,omitempty"` +} + +// DeleteKbContentsDTO PATCH body schema of Delete Operation in UpdateKb +type DeleteKbContentsDTO struct { + // Ids - List of Qna Ids to be deleted + Ids *[]int32 `json:"ids,omitempty"` + // Sources - List of sources to be deleted from knowledgebase. + Sources *[]string `json:"sources,omitempty"` +} + +// EndpointKeysDTO schema for EndpointKeys generate/refresh operations. +type EndpointKeysDTO struct { + autorest.Response `json:"-"` + // PrimaryEndpointKey - Primary Access Key. + PrimaryEndpointKey *string `json:"primaryEndpointKey,omitempty"` + // SecondaryEndpointKey - Secondary Access Key. + SecondaryEndpointKey *string `json:"secondaryEndpointKey,omitempty"` + // InstalledVersion - Current version of runtime. + InstalledVersion *string `json:"installedVersion,omitempty"` + // LastStableVersion - Latest version of runtime. + LastStableVersion *string `json:"lastStableVersion,omitempty"` +} + +// Error the error object. As per Microsoft One API guidelines - +// https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. +type Error struct { + // Code - One of a server-defined set of error codes. Possible values include: 'BadArgument', 'Forbidden', 'NotFound', 'KbNotFound', 'Unauthorized', 'Unspecified', 'EndpointKeysError', 'QuotaExceeded', 'QnaRuntimeError', 'SKULimitExceeded', 'OperationNotFound', 'ServiceError', 'ValidationFailure', 'ExtractionFailure' + Code ErrorCodeType `json:"code,omitempty"` + // Message - A human-readable representation of the error. + Message *string `json:"message,omitempty"` + // Target - The target of the error. + Target *string `json:"target,omitempty"` + // Details - An array of details about specific errors that led to this reported error. + Details *[]Error `json:"details,omitempty"` + // InnerError - An object containing more specific information than the current object about the error. + InnerError *InnerErrorModel `json:"innerError,omitempty"` +} + +// ErrorResponse error response. As per Microsoft One API guidelines - +// https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. +type ErrorResponse struct { + // Error - The error object. + Error *ErrorResponseError `json:"error,omitempty"` +} + +// ErrorResponseError the error object. +type ErrorResponseError struct { + // Code - One of a server-defined set of error codes. Possible values include: 'BadArgument', 'Forbidden', 'NotFound', 'KbNotFound', 'Unauthorized', 'Unspecified', 'EndpointKeysError', 'QuotaExceeded', 'QnaRuntimeError', 'SKULimitExceeded', 'OperationNotFound', 'ServiceError', 'ValidationFailure', 'ExtractionFailure' + Code ErrorCodeType `json:"code,omitempty"` + // Message - A human-readable representation of the error. + Message *string `json:"message,omitempty"` + // Target - The target of the error. + Target *string `json:"target,omitempty"` + // Details - An array of details about specific errors that led to this reported error. + Details *[]Error `json:"details,omitempty"` + // InnerError - An object containing more specific information than the current object about the error. + InnerError *InnerErrorModel `json:"innerError,omitempty"` +} + +// FileDTO DTO to hold details of uploaded files. +type FileDTO struct { + // FileName - File name. Supported file types are ".tsv", ".pdf", ".txt", ".docx", ".xlsx". + FileName *string `json:"fileName,omitempty"` + // FileURI - Public URI of the file. + FileURI *string `json:"fileUri,omitempty"` +} + +// InnerErrorModel an object containing more specific information about the error. As per Microsoft One API +// guidelines - +// https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. +type InnerErrorModel struct { + // Code - A more specific error code than was provided by the containing error. + Code *string `json:"code,omitempty"` + // InnerError - An object containing more specific information than the current object about the error. + InnerError *InnerErrorModel `json:"innerError,omitempty"` +} + +// KnowledgebaseDTO response schema for CreateKb operation. +type KnowledgebaseDTO struct { + autorest.Response `json:"-"` + // ID - Unique id that identifies a knowledgebase. + ID *string `json:"id,omitempty"` + // HostName - URL host name at which the knowledgebase is hosted. + HostName *string `json:"hostName,omitempty"` + // LastAccessedTimestamp - Time stamp at which the knowledgebase was last accessed (UTC). + LastAccessedTimestamp *string `json:"lastAccessedTimestamp,omitempty"` + // LastChangedTimestamp - Time stamp at which the knowledgebase was last modified (UTC). + LastChangedTimestamp *string `json:"lastChangedTimestamp,omitempty"` + // LastPublishedTimestamp - Time stamp at which the knowledgebase was last published (UTC). + LastPublishedTimestamp *string `json:"lastPublishedTimestamp,omitempty"` + // Name - Friendly name of the knowledgebase. + Name *string `json:"name,omitempty"` + // UserID - User who created / owns the knowledgebase. + UserID *string `json:"userId,omitempty"` + // Urls - URL sources from which Q-A were extracted and added to the knowledgebase. + Urls *[]string `json:"urls,omitempty"` + // Sources - Custom sources from which Q-A were extracted or explicitly added to the knowledgebase. + Sources *[]string `json:"sources,omitempty"` +} + +// KnowledgebasesDTO collection of knowledgebases owned by a user. +type KnowledgebasesDTO struct { + autorest.Response `json:"-"` + // Knowledgebases - Collection of knowledgebase records. + Knowledgebases *[]KnowledgebaseDTO `json:"knowledgebases,omitempty"` +} + +// MetadataDTO name - value pair of metadata. +type MetadataDTO struct { + // Name - Metadata name. + Name *string `json:"name,omitempty"` + // Value - Metadata value. + Value *string `json:"value,omitempty"` +} + +// Operation record to track long running operation. +type Operation struct { + autorest.Response `json:"-"` + // OperationState - Operation state. Possible values include: 'Failed', 'NotStarted', 'Running', 'Succeeded' + OperationState OperationStateType `json:"operationState,omitempty"` + // CreatedTimestamp - Timestamp when the operation was created. + CreatedTimestamp *string `json:"createdTimestamp,omitempty"` + // LastActionTimestamp - Timestamp when the current state was entered. + LastActionTimestamp *string `json:"lastActionTimestamp,omitempty"` + // ResourceLocation - Relative URI to the target resource location for completed resources. + ResourceLocation *string `json:"resourceLocation,omitempty"` + // UserID - User Id + UserID *string `json:"userId,omitempty"` + // OperationID - Operation Id. + OperationID *string `json:"operationId,omitempty"` + // ErrorResponse - Error details in case of failures. + ErrorResponse *ErrorResponse `json:"errorResponse,omitempty"` +} + +// QnADocumentsDTO list of QnADTO +type QnADocumentsDTO struct { + autorest.Response `json:"-"` + // QnaDocuments - List of answers. + QnaDocuments *[]QnADTO `json:"qnaDocuments,omitempty"` +} + +// QnADTO q-A object. +type QnADTO struct { + // ID - Unique id for the Q-A. + ID *int32 `json:"id,omitempty"` + // Answer - Answer text + Answer *string `json:"answer,omitempty"` + // Source - Source from which Q-A was indexed. eg. https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs + Source *string `json:"source,omitempty"` + // Questions - List of questions associated with the answer. + Questions *[]string `json:"questions,omitempty"` + // Metadata - List of metadata associated with the answer. + Metadata *[]MetadataDTO `json:"metadata,omitempty"` +} + +// ReplaceKbDTO post body schema for Replace KB operation. +type ReplaceKbDTO struct { + // QnAList - List of Q-A (QnADTO) to be added to the knowledgebase. Q-A Ids are assigned by the service and should be omitted. + QnAList *[]QnADTO `json:"qnAList,omitempty"` +} + +// UpdateKbContentsDTO PATCH body schema for Update operation in Update Kb +type UpdateKbContentsDTO struct { + // Name - Friendly name for the knowledgebase. + Name *string `json:"name,omitempty"` + // QnaList - List of Q-A (UpdateQnaDTO) to be added to the knowledgebase. + QnaList *[]UpdateQnaDTO `json:"qnaList,omitempty"` + // Urls - List of existing URLs to be refreshed. The content will be extracted again and re-indexed. + Urls *[]string `json:"urls,omitempty"` +} + +// UpdateKbOperationDTO contains list of QnAs to be updated +type UpdateKbOperationDTO struct { + // Add - An instance of CreateKbInputDTO for add operation + Add *UpdateKbOperationDTOAdd `json:"add,omitempty"` + // Delete - An instance of DeleteKbContentsDTO for delete Operation + Delete *UpdateKbOperationDTODelete `json:"delete,omitempty"` + // Update - An instance of UpdateKbContentsDTO for Update Operation + Update *UpdateKbOperationDTOUpdate `json:"update,omitempty"` +} + +// UpdateKbOperationDTOAdd an instance of CreateKbInputDTO for add operation +type UpdateKbOperationDTOAdd struct { + // QnaList - List of QNA to be added to the index. Ids are generated by the service and should be omitted. + QnaList *[]QnADTO `json:"qnaList,omitempty"` + // Urls - List of URLs to be added to knowledgebase. + Urls *[]string `json:"urls,omitempty"` + // Files - List of files to be added to knowledgebase. + Files *[]FileDTO `json:"files,omitempty"` +} + +// UpdateKbOperationDTODelete an instance of DeleteKbContentsDTO for delete Operation +type UpdateKbOperationDTODelete struct { + // Ids - List of Qna Ids to be deleted + Ids *[]int32 `json:"ids,omitempty"` + // Sources - List of sources to be deleted from knowledgebase. + Sources *[]string `json:"sources,omitempty"` +} + +// UpdateKbOperationDTOUpdate an instance of UpdateKbContentsDTO for Update Operation +type UpdateKbOperationDTOUpdate struct { + // Name - Friendly name for the knowledgebase. + Name *string `json:"name,omitempty"` + // QnaList - List of Q-A (UpdateQnaDTO) to be added to the knowledgebase. + QnaList *[]UpdateQnaDTO `json:"qnaList,omitempty"` + // Urls - List of existing URLs to be refreshed. The content will be extracted again and re-indexed. + Urls *[]string `json:"urls,omitempty"` +} + +// UpdateMetadataDTO PATCH Body schema to represent list of Metadata to be updated +type UpdateMetadataDTO struct { + // Delete - List of Metadata associated with answer to be deleted + Delete *[]MetadataDTO `json:"delete,omitempty"` + // Add - List of Metadat associated with answer to be added + Add *[]MetadataDTO `json:"add,omitempty"` +} + +// UpdateQnaDTO PATCH Body schema for Update Qna List +type UpdateQnaDTO struct { + // ID - Unique id for the Q-A + ID *int32 `json:"id,omitempty"` + // Answer - Answer text + Answer *string `json:"answer,omitempty"` + // Source - Source from which Q-A was indexed. eg. https://docs.microsoft.com/en-us/azure/cognitive-services/QnAMaker/FAQs + Source *string `json:"source,omitempty"` + // Questions - List of questions associated with the answer. + Questions *UpdateQnaDTOQuestions `json:"questions,omitempty"` + // Metadata - List of metadata associated with the answer to be updated + Metadata *UpdateQnaDTOMetadata `json:"metadata,omitempty"` +} + +// UpdateQnaDTOMetadata list of metadata associated with the answer to be updated +type UpdateQnaDTOMetadata struct { + // Delete - List of Metadata associated with answer to be deleted + Delete *[]MetadataDTO `json:"delete,omitempty"` + // Add - List of Metadat associated with answer to be added + Add *[]MetadataDTO `json:"add,omitempty"` +} + +// UpdateQnaDTOQuestions list of questions associated with the answer. +type UpdateQnaDTOQuestions struct { + // Add - List of questions to be added + Add *[]string `json:"add,omitempty"` + // Delete - List of questions to be deleted. + Delete *[]string `json:"delete,omitempty"` +} + +// UpdateQuestionsDTO PATCH Body schema for Update Kb which contains list of questions to be added and +// deleted +type UpdateQuestionsDTO struct { + // Add - List of questions to be added + Add *[]string `json:"add,omitempty"` + // Delete - List of questions to be deleted. + Delete *[]string `json:"delete,omitempty"` +} + +// WordAlterationsDTO collection of word alterations. +type WordAlterationsDTO struct { + autorest.Response `json:"-"` + // WordAlterations - Collection of word alterations. + WordAlterations *[]AlterationsDTO `json:"wordAlterations,omitempty"` +} diff --git a/services/cognitiveservices/v4.0/qnamaker/operations.go b/services/cognitiveservices/v4.0/qnamaker/operations.go new file mode 100644 index 000000000000..f22ef44319c2 --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/operations.go @@ -0,0 +1,108 @@ +package qnamaker + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/tracing" + "net/http" +) + +// OperationsClient is the an API for QnAMaker Service +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(endpoint string) OperationsClient { + return OperationsClient{New(endpoint)} +} + +// GetDetails sends the get details request. +// Parameters: +// operationID - operation id. +func (client OperationsClient) GetDetails(ctx context.Context, operationID string) (result Operation, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.GetDetails") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetDetailsPreparer(ctx, operationID) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.OperationsClient", "GetDetails", nil, "Failure preparing request") + return + } + + resp, err := client.GetDetailsSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "qnamaker.OperationsClient", "GetDetails", resp, "Failure sending request") + return + } + + result, err = client.GetDetailsResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "qnamaker.OperationsClient", "GetDetails", resp, "Failure responding to request") + } + + return +} + +// GetDetailsPreparer prepares the GetDetails request. +func (client OperationsClient) GetDetailsPreparer(ctx context.Context, operationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "operationId": autorest.Encode("path", operationID), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/qnamaker/v4.0", urlParameters), + autorest.WithPathParameters("/operations/{operationId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetDetailsSender sends the GetDetails request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) GetDetailsSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetDetailsResponder handles the response to the GetDetails request. The method always +// closes the http.Response Body. +func (client OperationsClient) GetDetailsResponder(resp *http.Response) (result Operation, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/cognitiveservices/v4.0/qnamaker/qnamakerapi/interfaces.go b/services/cognitiveservices/v4.0/qnamaker/qnamakerapi/interfaces.go new file mode 100644 index 000000000000..06e82a2d61e1 --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/qnamakerapi/interfaces.go @@ -0,0 +1,61 @@ +package qnamakerapi + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/services/cognitiveservices/v4.0/qnamaker" + "github.com/Azure/go-autorest/autorest" +) + +// EndpointClientAPI contains the set of methods on the EndpointClient type. +type EndpointClientAPI interface { + GetKeys(ctx context.Context) (result qnamaker.EndpointKeysDTO, err error) + RefreshKeys(ctx context.Context, keyType string) (result qnamaker.EndpointKeysDTO, err error) +} + +var _ EndpointClientAPI = (*qnamaker.EndpointClient)(nil) + +// AlterationsClientAPI contains the set of methods on the AlterationsClient type. +type AlterationsClientAPI interface { + Get(ctx context.Context) (result qnamaker.WordAlterationsDTO, err error) + Replace(ctx context.Context, wordAlterations qnamaker.WordAlterationsDTO) (result autorest.Response, err error) +} + +var _ AlterationsClientAPI = (*qnamaker.AlterationsClient)(nil) + +// KnowledgebaseClientAPI contains the set of methods on the KnowledgebaseClient type. +type KnowledgebaseClientAPI interface { + Create(ctx context.Context, createKbPayload qnamaker.CreateKbDTO) (result qnamaker.Operation, err error) + Delete(ctx context.Context, kbID string) (result autorest.Response, err error) + Download(ctx context.Context, kbID string, environment qnamaker.EnvironmentType) (result qnamaker.QnADocumentsDTO, err error) + GetDetails(ctx context.Context, kbID string) (result qnamaker.KnowledgebaseDTO, err error) + ListAll(ctx context.Context) (result qnamaker.KnowledgebasesDTO, err error) + Publish(ctx context.Context, kbID string) (result autorest.Response, err error) + Replace(ctx context.Context, kbID string, replaceKb qnamaker.ReplaceKbDTO) (result autorest.Response, err error) + Update(ctx context.Context, kbID string, updateKb qnamaker.UpdateKbOperationDTO) (result qnamaker.Operation, err error) +} + +var _ KnowledgebaseClientAPI = (*qnamaker.KnowledgebaseClient)(nil) + +// OperationsClientAPI contains the set of methods on the OperationsClient type. +type OperationsClientAPI interface { + GetDetails(ctx context.Context, operationID string) (result qnamaker.Operation, err error) +} + +var _ OperationsClientAPI = (*qnamaker.OperationsClient)(nil) diff --git a/services/cognitiveservices/v4.0/qnamaker/version.go b/services/cognitiveservices/v4.0/qnamaker/version.go new file mode 100644 index 000000000000..e8c39284ae65 --- /dev/null +++ b/services/cognitiveservices/v4.0/qnamaker/version.go @@ -0,0 +1,30 @@ +package qnamaker + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + version.Number + " qnamaker/4.0" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +}