Code Monkey home page Code Monkey logo

cognitive-services-qnamaker-csharp's Introduction

page_type languages products description urlFragment
sample
csharp
html
azure
These REST samples show you how to programmatically create, update, publish,
cognitive-services-qnamaker-csharp

Cognitive Services QnA Maker Samples in C#

These REST samples show you how to programmatically create, update, publish, and replace a QnA Maker knowledge base, amongst many other ways to interact with it. All samples are in C#. To view these same samples in other languages:

cognitive-services-qnamaker-java

cognitive-services-qnamaker-nodejs

cognitive-services-qnamaker-python

Features

Included are the following samples:

All REST samples revolve around what you can do with a knowledge base, which is made up of FAQs or product manuals where there is a question and an answer. QnA Maker gives you more control over how to answer questions by allowing you to train a chat bot to give answers in a variety of ways that feels more like natural, conversational exchanges.

Getting Started

Prerequisites

For each sample, a subscription key is required from your Azure Portal account.

  • To create a new account/resource for QnA Maker, see Create a Cognitive Services API account in the Azure portal. You may need to 'Search in Marketplace' for QnA Maker if you don't see it in the list given.
  • For existing accounts, the key can be found in your Azure Portal dashboard in your QnA Maker resource under Resource Management > Keys. You'll need this key to add to your sample before running.

With the exception of creating a new knowledge base, these samples will require your QnA Maker account knowledge base ID. To find your knowledge base ID, go to My knowledge bases and select View Code on the right. You'll see the http request and your knowledge base ID is in the topmost line: for example, POST /knowledgebases/2700e6b9-91a1-41e9-a958-6d1a98735b10/.... Use only the ID.

Run sample

  1. Create a C# Console App (.NET Framework) in Visual Studio 2017, then add the sample you want to try to Program.cs. For example, if you want to try create-new-knowledge-base.cs. Copy/paste the code from there into your Program.cs.

  2. You can either create one console app per sample, or add a bunch of samples to one console app as projects, then run them separately.

  3. Install the Newtonsoft.Json NuGet package.

  4. Read the comments in the code sample to see where you add your keys.

  5. Run the sample.

Quickstart

Web app bot

References

QnA Maker V4.0

cognitive-services-qnamaker-csharp's People

Contributors

diberry avatar erhopf avatar gurvsing avatar microsoftopensource avatar msftgits avatar rb2531 avatar sahithikkss avatar v-jaswel avatar v-rajagt-zz avatar wiazur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cognitive-services-qnamaker-csharp's Issues

How to train QnA Maker using the portal if the correct answer is not among the top 3 ranked answers?

We have a knowledge base with near 1000 answers and a average of 15 alternate questions for each one of them. We are training the base both adding alternate questions as trying to indicate the correct answer using the portal.

We have struggling to improve the precision but without relevant success yet. An important problem is that base has a lot of similar answers between themselves, many times the difference among them is only an year (e.g. 2014 or 2018).

Some times when we use the GenerateAnswer API we need increase the parameter top a lot to receive the correct answer. For some questions we need assign the value 500 for top parameter, otherwise we get other answers with high scores, but still incorrect.

We thought that we could increase that results using the portal to train the knowledge base indicating the correct answer, but when we are trying it, we get just the first three top ranked answers, all incorrect.

*Note: We already migrated a test base to new approach (Language services/Question Answering) hoping that could be help us, but the problem stays, actually a bit worst.

How can we deal with this kind of situation? Can we change the top parameter value used by the portal? Are there another ways we can use to improve the rank?

Same error all the time

Please provide us with the following information:

This issue is for a: (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

To reproduce just follow steps in Batch test with tool at https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/how-to/test-knowledge-base?tabs=v1#batch-test-with-tool
KB created with defined settings and from multi-turn sample.docx
** I have also got the same error with any other of my KBs, on the same QnA instance.

Any log messages given by the failure

For each line n sample.docx I got the following message:

Error processing line : 1, System.AggregateException: One or more errors occurred. (A task was canceled.)
---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at batchtesting.Program.Main(String[] args) in C:\Work\gurvsing\cognitive-services-qnamaker-csharp\documentation-samples\batchtesting\Program.cs:line 18

Expected/desired behavior

results in out.tsv

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Windows Server 2016 Datacenter

Versions

Mention any other details that might be useful

QnA Maker: Tier=Free F0
Search Service: Tier=Free, Replica 1, Partition= 1, Search Units= 1
App Service Plan: Tier=F1:Free, Apps/Slots= 1/0, OS=Windows
App Service: Tier=F1:Free

Thanks! We'll be in touch soon.

Qna Maker api to fetch all the questions in qnaMaker

Hi,
How do i get all the questions in the qnaMaker via an API.
There are about 1000 questions in my QnaMaker Knowledge i need to fetch all the questions via an api and store them in a SqlServer Db.

Thank you.

Replace QnA Maker Knowledgebase with Prompts

Hello Team,

I am trying to replace a knowledge base(multi turn enabled). But in API call i am getting the Error saying invalid prompts given.
It will be great help if you will provide the sample Json for Replace a qnA qith multiturn enabled

Need to Add QnA Programmatically

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [X ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Need to Add QnA Programmatically .. This returns UnAuthorized..
public async Task UpdateQueryQnABot(string newQuestion, string newAnswer)
{
string strResponse = "";
// Create the QnAKnowledgeBase that contains the new entry
QnAKnowledgeBase objQnAKnowledgeBase = new QnAKnowledgeBase();
QnaPair objQnaPair = new QnaPair();

        objQnaPair.question = newQuestion;
        objQnaPair.answer = newAnswer;
       // if (paramMode == Mode.Add)
       // {
            Add objAdd = new Add();
            objAdd.qnaPairs = new List<QnaPair>();
            objAdd.urls = new List<string>();
            objAdd.qnaPairs.Add(objQnaPair);
            objQnAKnowledgeBase.add = objAdd;
       // }

        using (System.Net.Http.HttpClient client =
            new System.Net.Http.HttpClient())
        {
            string RequestURI = String.Format("{0}{1}{2}{3}? ",
             @"https://westus.api.cognitive.microsoft.com/",
              @"qnamaker/v4.0/",
               @"knowledgebases/",
               knowledgeBaseId);
            //https://westus.api.cognitive.microsoft.com/qnamaker/v4.0/knowledgebases/
            //string RequestURI = qnaServiceHostName + "/qnamaker/knowledgebases/" + knowledgeBaseId ;
            //string questionJSON = @"{'question': '" + question + "'}";


            using (HttpRequestMessage request =
                new HttpRequestMessage(new HttpMethod("PATCH"), RequestURI))
            {
                request.Content = new StringContent(
                    JsonConvert.SerializeObject(objQnAKnowledgeBase),
                    System.Text.Encoding.UTF8, "application/json");
                request.Content.Headers.Add(
                    "Ocp-Apim-Subscription-Key", endpointKey);
                HttpResponseMessage response = await client.SendAsync(request);
                if (response.IsSuccessStatusCode)
                {
                    strResponse = $"Operation successfully completed.";
                }
                else
                {
                    string responseContent = 
                        await response.Content.ReadAsStringAsync();
                    strResponse = responseContent;
                }

Any log messages given by the failure

Expected/desired behavior

Using API to Create KB stripes out basic HTML supported tags

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Using the https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/create-new-kb-csharp sample create simple question and answer where there is a simple

tag t the answer. Then exeecute the code.

Any log messages given by the failure

The simple

tag is removed when viewing the KB in QnAMaker.ai.

Expected/desired behavior

The new imported KB should have the simple

tag.

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

Versions

Windows 10

Mention any other details that might be useful

If I use the CSV import the tag is preserved or if I manually update the answer. I need to use the API since there is a log of content and doing it manually is not an option. The CSV option seems only to allow one question\answer which is also not an option since my KB has multiple questions.


Thanks! We'll be in touch soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.