コード例 #1
0
        private async Task CognitiveServices_QnA_MigrationGuide_Runtime()
        {
            #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateRuntimeClient
            EndpointKeyServiceClientCredentials credential = new EndpointKeyServiceClientCredentials("{ApiKey}");

            QnAMakerRuntimeClient client = new QnAMakerRuntimeClient(credential)
            {
                RuntimeEndpoint = "{QnaMakerEndpoint}"
            };
            #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_CreateRuntimeClient

            #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_QueryKnowledgeBase
            QueryDTO queryDTO = new QueryDTO();
            queryDTO.Question = "{Question}";

            QnASearchResultList response = await client.Runtime.GenerateAnswerAsync("{knowledgebase-id}", queryDTO);

            #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_QueryKnowledgeBase

            #region Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_Chat
            QueryDTO queryDTOFollowUp = new QueryDTO();
            queryDTOFollowUp.Context = new QueryDTOContext(previousQnaId: 1);

            QnASearchResultList responseFollowUp = await client.Runtime.GenerateAnswerAsync("{knowledgebase-id}", queryDTO);

            #endregion Snippet:CognitiveServices_QnA_Maker_Snippets_MigrationGuide_Chat
        }
コード例 #2
0
        // <Main>
        static void Main(string[] args)
        {
            // <Resourcevariables>
            var authoringKey = "QNA_MAKER_SUBSCRIPTION_KEY";
            var authoringURL = "QNA_MAKER_ENDPOINT";
            var queryingURL  = "QNA_MAKER_RUNTIME_ENDPOINT";
            // </Resourcevariables>


            // <AuthorizationAuthor>
            var client = new QnAMakerClient(new ApiKeyServiceClientCredentials(authoringKey))
            {
                Endpoint = authoringURL
            };
            // </AuthorizationAuthor>

            var kbId = CreateSampleKb(client).Result;

            UpdateKB(client, kbId).Wait();
            PublishKb(client, kbId).Wait();
            DownloadKb(client, kbId).Wait();
            var primaryQueryEndpointKey = GetQueryEndpointKey(client).Result;

            // <AuthorizationQuery>
            var runtimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(primaryQueryEndpointKey))
            {
                RuntimeEndpoint = queryingURL
            };

            // </AuthorizationQuery>

            GenerateAnswer(runtimeClient, kbId).Wait();
            DeleteKB(client, kbId).Wait();
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="QnaServiceProvider"/> class.
 /// </summary>
 /// <param name="configurationProvider">ConfigurationProvider fetch and store information in storage table.</param>
 /// <param name="optionsAccessor">A set of key/value application configuration properties.</param>
 /// <param name="qnaMakerClient">Qna service client.</param>
 /// <param name="qnaMakerRuntimeClient">Qna service runtime client.</param>
 public QnaServiceProvider(IConfigurationDataProvider configurationProvider, IOptionsMonitor<QnAMakerSettings> optionsAccessor, IQnAMakerClient qnaMakerClient, QnAMakerRuntimeClient qnaMakerRuntimeClient)
 {
     this.configurationProvider = configurationProvider;
     this.qnaMakerClient = qnaMakerClient;
     this.options = optionsAccessor.CurrentValue;
     this.qnaMakerRuntimeClient = qnaMakerRuntimeClient;
 }
コード例 #4
0
        public async Task <QnASearchResultList> AnswerQuestion(string question, string userId, int resultCount = 1)
        {
            //From QnA Knowledgebase - embedded GUID in POST portion
            var runtimeKB = _configuration["QNA_KB_ID"];
            //From QnA Knowledgebase - HOST
            var runtimeEndpoint = _configuration["QNA_RuntimeEndpoint"];
            //From QnA Knowledgebase - Authorization Endpoint Key
            var runtimeKey = _configuration["QNA_RuntimeKey"];

            var runtimeCreds = new EndpointKeyServiceClientCredentials(runtimeKey);

            //Runtime client for asking questions
            using (QnAMakerRuntimeClient rtClient = new QnAMakerRuntimeClient(runtimeCreds)
            {
                RuntimeEndpoint = runtimeEndpoint
            })
            {
                QueryDTO query = new QueryDTO()
                {
                    Question       = question,   //The text of the question
                    ScoreThreshold = 0.55,       //The minimum relevance score to accept
                    Top            = resultCount //How many answers to return, maximum
                };

                return(await rtClient.Runtime.GenerateAnswerAsync(runtimeKB, query).ConfigureAwait(false));
            }
        }
コード例 #5
0
        private async void CommandBinding_Executed_CheckConnection(object sender, ExecutedRoutedEventArgs e)
        {
            string EndPoint = Properties.Settings.Default.EndPoint;
            string Key      = Properties.Settings.Default.Key;
            string Id       = Properties.Settings.Default.Id;

            QnAMakerRuntimeClient client = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Key))
            {
                RuntimeEndpoint = EndPoint
            };

            try
            {
                string pregunta = "hola";
                QnASearchResultList response = await client.Runtime.GenerateAnswerAsync(Id, new QueryDTO { Question = pregunta });

                string respuesta = response.Answers[0].Answer;

                MessageBox.Show("Conexion realizada con exito", "Comprobar conexion", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("No se ha podido completar la conexion...", "Comprobar conexion", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #6
0
        private async void MandarMensaje_CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            mensajes.Add(new Mensaje(false, ChatTextBox.Text));
            Mensaje mensajeBot = new Mensaje(true, "Pensando...");

            mensajes.Add(mensajeBot);

            string respuesta = "";

            try
            {
                var cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Properties.Settings.Default.EndPointKey))
                {
                    RuntimeEndpoint = Properties.Settings.Default.EndPoint
                };
                QnASearchResultList response = await cliente.Runtime.GenerateAnswerAsync(Properties.Settings.Default.KnowledgeBaseId, new QueryDTO { Question = ChatTextBox.Text });

                respuesta = response.Answers[0].Answer;
            }
            catch (IOException)
            {
                respuesta = "Estoy muy cansado para hablar";
            }

            mensajeBot.Texto = respuesta;
            ChatTextBox.Text = "";
            ChatScrollViewer.ScrollToVerticalOffset(ChatScrollViewer.ExtentHeight);
        }
コード例 #7
0
        // <Main>
        static void Main(string[] args)
        {
            var authoringKey = "REPLACE-WITH-YOUR-QNA-MAKER-KEY";
            var resourceName = "REPLACE-WITH-YOUR-RESOURCE-NAME";

            // <AuthorizationAuthoring>
            var client = new QnAMakerClient(new ApiKeyServiceClientCredentials(authoringKey))
            {
                Endpoint = $"https://{resourceName}.cognitiveservices.azure.com"
            };
            // </AuthorizationAuthoring>

            var kbId = CreateSampleKb(client).Result;

            UpdateKB(client, kbId).Wait();
            PublishKb(client, kbId).Wait();
            DownloadKb(client, kbId).Wait();
            var primaryPredictionEndpointKey = GetPredictionEndpointKey(client).Result;

            // <AuthorizationPrediction>
            var runtimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(primaryPredictionEndpointKey))
            {
                RuntimeEndpoint = $"https://{resourceName}.azurewebsites.net"
            };

            // </AuthorizationPrediction>

            GenerateAnswer(runtimeClient, kbId).Wait();
            DeleteKB(client, kbId).Wait();
        }
コード例 #8
0
        private async Task ObtenRespuestaBotAsync(string pregunta, int indice)
        {
            try
            {
                string EndPoint               = Properties.Settings.Default.EndPoint;
                string EndPointKey            = Properties.Settings.Default.EndPointKey;
                string KnowledgeBaseId        = Properties.Settings.Default.KnowledgeBaseId;
                QnAMakerRuntimeClient cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(EndPointKey))
                {
                    RuntimeEndpoint = EndPoint
                };

                //Realizamos la pregunta a la API
                QnASearchResultList response = await(cliente.Runtime.GenerateAnswerAsync(KnowledgeBaseId, new QueryDTO {
                    Question = pregunta
                }));
                string respuesta = response.Answers[0].Answer;
                mensajes[indice].Mensaje = respuesta;
            }
            catch (Exception ex)
            {
                string           messageBoxText = ex.Message;
                string           caption        = "Error Bot";
                MessageBoxButton button         = MessageBoxButton.OK;
                MessageBoxImage  icon           = MessageBoxImage.Error;
                MessageBox.Show(messageBoxText, caption, button, icon);
                mensajes[indice].Mensaje = "No he podifo obtener una respuesta.";
            }
        }
コード例 #9
0
        private async void ComprobarConexion_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                string EndPoint               = Properties.Settings.Default.EndPoint;
                string EndPointKey            = Properties.Settings.Default.EndPointKey;
                string KnowledgeBaseId        = Properties.Settings.Default.KnowledgeBaseId;
                QnAMakerRuntimeClient cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(EndPointKey))
                {
                    RuntimeEndpoint = EndPoint
                };

                //Realizamos la pregunta a la API
                QnASearchResultList response = await(cliente.Runtime.GenerateAnswerAsync(KnowledgeBaseId, new QueryDTO {
                    Question = "Hola"
                }));
                _ = response.Answers[0].Answer;

                string           messageBoxText = "Conexión correcta con el servidor del Bot";
                string           caption        = "Comprobar conexión";
                MessageBoxButton button         = MessageBoxButton.OK;
                MessageBoxImage  icon           = MessageBoxImage.Information;
                MessageBox.Show(messageBoxText, caption, button, icon);
            }
            catch (Exception)
            {
                string           caption = "Error Bot";
                MessageBoxButton button  = MessageBoxButton.OK;
                MessageBoxImage  icon    = MessageBoxImage.Error;
                MessageBox.Show("No se ha podido establecer la conexión con el servidor del bot", caption, button, icon);
            }
        }
コード例 #10
0
        /// <summary>
        /// Service Collection extension.
        ///
        /// Injects concrete implementation of QnAService.
        /// </summary>
        /// <param name="services">Service collection.</param>
        /// <param name="configuration">Configuration.</param>
        /// <returns>Service Collection.</returns>
        public static IServiceCollection AddQnAService(this IServiceCollection services, IConfiguration configuration)
        {
            // Add QnAMakerClient
            var subscriptionKey = configuration.GetValue <string>("QnAMaker:SubscriptionKey");
            var endpoint        = configuration.GetValue <string>("QnAMaker:Endpoint");
            var qnaMakerClient  = new QnAMakerClient(new ApiKeyServiceClientCredentials(subscriptionKey))
            {
                Endpoint = endpoint,
            };

            services.AddSingleton <IQnAMakerClient>(qnaMakerClient);

            // Add QnAMakerRuntimeClient
            var runtimeEndpoint       = configuration.GetValue <string>("QnAMaker:RuntimeEndpoint");
            var endpointKey           = configuration.GetValue <string>("QnAMaker:EndpointKey");
            var qnaMakerRuntimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(endpointKey))
            {
                RuntimeEndpoint = runtimeEndpoint,
            };

            services.AddSingleton <IQnAMakerRuntimeClient>(qnaMakerRuntimeClient);

            // Add QnAServiceSettings
            var qnaServiceSettings = new QnAServiceSettings()
            {
                ScoreThreshold  = configuration.GetValue <int>("QnAMaker:ScoreThreshold"),
                KnowledgeBaseId = configuration.GetValue <string>("QnAMaker:KnowledgeBaseId"),
            };

            services.AddSingleton <IQnAServiceSettings>(qnaServiceSettings);

            // Add QnAService
            services.AddTransient <IQnAService, QnAService>();
            return(services);
        }
コード例 #11
0
        public async Task <string> MensajeRobot(string pregunta)
        {
            //Para usar la API QnA añadir el paquete NuGet
            //Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker

            //Creamos el cliente de QnA
            string EndPoint        = Properties.Settings.Default.EndPoint;
            string EndPointKey     = Properties.Settings.Default.EndPointKey;
            string KnowledgeBaseId = Properties.Settings.Default.KnowledgeBaseId;
            var    cliente         = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(EndPointKey))
            {
                RuntimeEndpoint = EndPoint
            };

            hayConexion = true;
            //Realizamos la pregunta a la API
            try
            {
                QnASearchResultList response = await cliente.Runtime.GenerateAnswerAsync(KnowledgeBaseId, new QueryDTO { Question = pregunta });

                return(response.Answers[0].Answer);
            }
            catch (Exception)
            {
                hayConexion = false;
                return(null);
            }
        }
コード例 #12
0
 public Bot()
 {
     cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Properties.Settings.Default.AzureBotKey))
     {
         RuntimeEndpoint = Properties.Settings.Default.AzureBotEndPoint
     };
     IsNotProcessing = true;
 }
コード例 #13
0
        // </DownloadKB>

        // <GenerateAnswer>
        private static async Task GenerateAnswer(QnAMakerRuntimeClient runtimeClient, string kbId)
        {
            var response = await runtimeClient.Runtime.GenerateAnswerAsync(kbId, new QueryDTO { Question = "How do I manage my knowledgebase?" });

            Console.WriteLine("Endpoint Response: {0}.", response.Answers[0].Answer);

            // Do something meaningful with answer
        }
コード例 #14
0
        // <Main>
        static void Main(string[] args)
        {
            // <AuthoringAuthorization>
            string subscriptionKey = "PASTE_YOUR_QNA_MAKER_AUTHORING_SUBSCRIPTION_KEY_HERE";
            string endpoint        = "PASTE_YOUR_QNA_MAKER_AUTHORING_ENDPOINT_HERE";

            // set tryPreview to 'true' for QnAMakerV2 resources
            bool tryPreview = false;

            var authoringClient = new QnAMakerClient(new ApiKeyServiceClientCredentials(subscriptionKey), tryPreview)
            {
                Endpoint = endpoint
            };
            // </AuthoringAuthorization>

            // <RuntimeAuthorization>
            string runtimeEndpoint = "PASTE_YOUR_QNA_MAKER_RUNTIME_ENDPOINT_HERE";

            if (tryPreview)
            {
                runtimeEndpoint = endpoint;
            }

            string endpointKey = GetQueryEndpointKey(authoringClient).Result;
            QnAMakerRuntimeClient runtimeClient;

            if (tryPreview)
            {
                runtimeClient = new QnAMakerRuntimeClient(new ApiKeyServiceClientCredentials(subscriptionKey), tryPreview)
                {
                    RuntimeEndpoint = runtimeEndpoint
                };
            }
            else
            {
                runtimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(endpointKey))
                {
                    RuntimeEndpoint = runtimeEndpoint
                };
            }
            // </RuntimeAuthorization>

            Console.WriteLine("Creating KB...");
            var kbId = CreateSampleKb(authoringClient).Result;

            Console.WriteLine("Created KB with ID " + kbId + ".");
            Console.WriteLine("Downloading KB...");
            DownloadKb(authoringClient, kbId).Wait();
            Console.WriteLine("Updating KB...");
            UpdateKB(authoringClient, kbId).Wait();
            Console.WriteLine("Publishing KB...");
            PublishKb(authoringClient, kbId).Wait();
            Console.WriteLine("Querying KB...");
            GenerateAnswer(runtimeClient, kbId).Wait();
            Console.WriteLine("Deleting KB...");
            DeleteKB(authoringClient, kbId).Wait();
        }
コード例 #15
0
        protected IQnAMakerRuntimeClient GetQnAMakerRuntimeClient(DelegatingHandler handler)
        {
            IQnAMakerRuntimeClient client = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(QnAMakerEndpointKey), handlers: handler)
            {
                RuntimeEndpoint = "https://myqnamakerapp.azurewebsites.net"
            };

            return(client);
        }
コード例 #16
0
        protected IQnAMakerRuntimeClient GetQnAMakerPreviewRuntimeClient(DelegatingHandler handler)
        {
            IQnAMakerRuntimeClient client = new QnAMakerRuntimeClient(new ApiKeyServiceClientCredentials(QnAMakerSubscriptionKey), isPreview: true, handlers: handler)
            {
                RuntimeEndpoint = "https://australiaeast.api.cognitive.microsoft.com"
            };

            return(client);
        }
コード例 #17
0
 public QnAService(string endPoint, string key, string id)
 {
     EndPoint = endPoint;
     Key      = key;
     Id       = id;
     cliente  = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Key))
     {
         RuntimeEndpoint = EndPoint
     };
 }
コード例 #18
0
 public EchoBot(IConfiguration config)
 {
     kbId      = config["QnAKnowledgeBase"];
     qnaClient = new QnAMakerRuntimeClient(
         new EndpointKeyServiceClientCredentials(
             config["QnAEndpointKey"]))
     {
         RuntimeEndpoint = $"https://{config["QnAEndpointHost"]}.azurewebsites.net"
     };
 }
コード例 #19
0
        public Bot()
        {
            string EndPoint = "https://botactividaddint.azurewebsites.net";
            string Key      = "9c1c31bb-5ad4-44c4-b5f9-c36256871454";

            server = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Key))
            {
                RuntimeEndpoint = EndPoint
            };
        }
コード例 #20
0
        static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                var exeName = "batchtesting.exe";
                Console.WriteLine($"Usage: {exeName} <tsv-inputfile> <runtime-hostname> <runtime-endpointkey> <tsv-outputfile>");
                Console.WriteLine($"{exeName} input.tsv https://myhostname.azurewebsites.net 5397A838-2B74-4E55-8111-D60ED1D7CF7F output.tsv");
                Console.WriteLine();

                return;
            }

            var i           = 0;
            var inputFile   = args[i++];
            var runtimeHost = args[i++];
            var endpointKey = args[i++];
            var outputFile  = args[i++];

            var inputQueries   = File.ReadAllLines(inputFile);
            var inputQueryData = inputQueries.Select(x => GetTsvData(x)).ToList();
            var runtimeClient  = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(endpointKey))
            {
                RuntimeEndpoint = runtimeHost
            };

            var lineNumber = 0;

            File.WriteAllText(outputFile, $"Line\tKbId\tQuery\tAnswer1\tScore1{Environment.NewLine}");
            foreach (var queryData in inputQueryData)
            {
                try
                {
                    lineNumber++;
                    var(queryDto, kbId) = GetQueryDTO(queryData);
                    var response = runtimeClient.Runtime.GenerateAnswer(kbId, queryDto);

                    var resultLine = new List <string>();
                    resultLine.Add(lineNumber.ToString());
                    resultLine.Add(kbId);
                    resultLine.Add(queryDto.Question);
                    foreach (var answer in response.Answers)
                    {
                        resultLine.Add(answer.Answer);
                        resultLine.Add(answer.Score.ToString());
                    }

                    var result = string.Join('\t', resultLine);
                    File.AppendAllText(outputFile, $"{result}{Environment.NewLine}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error processing line : {lineNumber}, {ex}");
                }
            }
        }
コード例 #21
0
ファイル: ClienteQNA.cs プロジェクト: DINT-ivamn/ChatBot
        public ClienteQnA()
        {
            string EndPoint = Properties.Settings.Default.Endpoint;
            string Key      = Properties.Settings.Default.Key;

            Id      = Properties.Settings.Default.Id;
            Cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Key))
            {
                RuntimeEndpoint = EndPoint
            };
        }
コード例 #22
0
ファイル: Robot.cs プロジェクト: DINT-MahrozJawad/ChatBox
        public Robot()
        {
            string EndPoint = "https://botmahroz.azurewebsites.net";
            string Key      = "a5e51ac1-8679-407f-9f42-1d70dadfd230";

            Id      = "ba514545-ce8f-4d28-8c96-0e30f9aa6f29";
            cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Key))
            {
                RuntimeEndpoint = EndPoint
            };
        }
コード例 #23
0
        // <Main>
        static void Main(string[] args)
        {
            // <Resourcevariables>
            var authoringKey = "REPLACE-WITH-YOUR-QNA-MAKER-KEY";
            var resourceName = "REPLACE-WITH-YOUR-RESOURCE-NAME";

            var authoringURL = $"https://{resourceName}.cognitiveservices.azure.com";
            var queryingURL  = $"https://{resourceName}.azurewebsites.net";
            // </Resourcevariables>

            // <TryPreview>
            // To be set to 'true' to use QnAMakerV2 Public Preview resources
            // Use the package Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker version 2.1.0-preview.1
            var tryPreview = false;
            // </TryPreview>


            // <AuthorizationAuthor>
            var client = new QnAMakerClient(new ApiKeyServiceClientCredentials(authoringKey), tryPreview)
            {
                Endpoint = authoringURL
            };
            // </AuthorizationAuthor>

            var kbId = CreateSampleKb(client).Result;

            UpdateKB(client, kbId).Wait();
            PublishKb(client, kbId).Wait();
            DownloadKb(client, kbId).Wait();
            var primaryQueryEndpointKey = GetQueryEndpointKey(client).Result;

            // <AuthorizationQuery>
            QnAMakerRuntimeClient runtimeClient;

            if (tryPreview)
            {
                runtimeClient = new QnAMakerRuntimeClient(new ApiKeyServiceClientCredentials(authoringKey), tryPreview)
                {
                    RuntimeEndpoint = authoringURL
                };
            }
            else
            {
                runtimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(primaryQueryEndpointKey))
                {
                    RuntimeEndpoint = queryingURL
                };
            }
            // </AuthorizationQuery>

            GenerateAnswer(runtimeClient, kbId).Wait();
            DeleteKB(client, kbId).Wait();
        }
コード例 #24
0
        public async Task <QnASearchResultList> Post(QueryDTO data)
        {
            var endpointKey = _configuration["QnAMakerEndpointKey"];
            var endpoint    = Environment.GetEnvironmentVariable("QnAMakerEndpoint");
            var kbId        = Environment.GetEnvironmentVariable("QnAMakerKbId");
            var client      = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(endpointKey))
            {
                RuntimeEndpoint = endpoint
            };
            var response = await client.Runtime.GenerateAnswerAsync(kbId, data);

            return(response);
        }
コード例 #25
0
        public async Task <IList <QnASearchResult> > GetQnAResponse(string question)
        {
            var subscriptionKey = configuration["QnAMakerAPIKey"];

            qnAMakerClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(subscriptionKey))
            {
                RuntimeEndpoint = configuration["QnAMakerEndpoint"]
            };

            var result = await qnAMakerClient.Runtime.GenerateAnswerAsync("5a60db98-441c-44b4-bbc0-59f70e960d54", new QueryDTO { Question = question });

            return(result.Answers);
        }
コード例 #26
0
        public MainWindow()
        {
            listaMensajes = new List <Mensaje>();
            InitializeComponent();
            string EndPoint = "https://botisma.azurewebsites.net";
            string Key      = "38249f96-77a1-46e2-adf4-f29195b93211";

            Id      = "e3c48047-80d3-4450-9231-ed4d0985840d";
            cliente = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Key))
            {
                RuntimeEndpoint = EndPoint
            };
            //MensajesItemsControl.DataContext = listaMensajes;
        }
コード例 #27
0
        public QnAHandler()
        {
            authoringKey = "";
            resourceName = "qnadietbot1";

            authoringURL = $"https://{resourceName}.cognitiveservices.azure.com";
            queryingURL  = $"https://{resourceName}.azurewebsites.net";

            primaryQueryEndpointKey = "";

            runtimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(primaryQueryEndpointKey))
            {
                RuntimeEndpoint = queryingURL
            };
        }
コード例 #28
0
        protected QnAMakerRuntimeClient GetQnAMakerRuntimeClient(DelegatingHandler handler)
        {
            // Do not initialize QnAMakerClient with EndpointKeyCredentials.
            // The following will fallback to constructor with ServiceCredentials instead.
            //       var client = new QnAMakerClient(new EndpointKeyServiceClientCredentials(QnAMakerEndpointKey), handler);
            // Because, it is a customized 'internal' contructor for backward compatibility with V2.x.x SDK
            // Use QnAMakerRuntimeClient instead like below

            var client = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(QnAMakerEndpointKey), handlers: handler)
            {
                RuntimeEndpoint = "https://sk4cs.azurewebsites.net"
            };

            return(client);
        }
コード例 #29
0
        //Conexión ------------------------------------------------------------------------------------------------------------------------------------------

        private async void Conexion()
        {
            string EndPoint = "https://botsergio.azurewebsites.net";
            string Key      = "164b4f7b-d067-439f-9ef9-20d58c3d5ec8";
            string Id       = "69e93d1d-6ccd-493d-8314-19e007646cf2";
            var    cliente  = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(Key))
            {
                RuntimeEndpoint = EndPoint
            };

            //Realizamos la pregunta a la API
            string pregunta = "Your question";
            QnASearchResultList response = await cliente.Runtime.GenerateAnswerAsync(Id, new QueryDTO { Question = pregunta });

            string respuesta = response.Answers[0].Answer;
        }
コード例 #30
0
        public static async Task <String> GetAnswer(string question)
        {
            var client = new QnAMakerClient(new ApiKeyServiceClientCredentials(authoringKey))
            {
                Endpoint = authoringURL
            };

            var primaryQueryEndpointKey = await GetQueryEndpointKey(client);

            var runtimeClient = new QnAMakerRuntimeClient(new EndpointKeyServiceClientCredentials(primaryQueryEndpointKey))
            {
                RuntimeEndpoint = queryingURL
            };
            var answer = await GenerateAnswer(runtimeClient, question);

            return(answer);
        }