botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[LUIS] Programmatic API?

Open sayyednazeer opened this issue 9 years ago • 46 comments

System Information (Required)

  • SDK Language: C#
  • Development Environment: AZURE

Issue Description

I want to create the APP, INTENTS, UTTERANCE ..... TRAIN and PUBLISH my app but not going to the www.luis.ai website.... i want to do it grammatically by calling its API and i came across this website https://westus.dev.cognitive.microsoft.com/docs/services/5890b47c39e2bb17b84a55ff/operations/5890b47c39e2bb052c5b9c2f

In that i am getting confused for what to pass in BODY parameter while making a post request for APP, INTENTS, UTTERANCE ..... TRAIN and PUBLISH.

So can any one please provide me some C# code for making all this post request with parameters . As i want every thing to do from my own application and not going to the luis.ai website.

sayyednazeer avatar Jul 04 '17 19:07 sayyednazeer

Is it possible to have a conversation in particular flow? I want a single luis utterance to have different response in a particular conversation flow, how can i do it? because my utterance hits to a single intent and luis can give a single response everytime. please give solution for C# code.

NehaShaikh786 avatar Jul 05 '17 14:07 NehaShaikh786

@sayyednazeer you have to learn how to call REST web services in C#, it is not Luis specific. You can have a look here for example: https://stackoverflow.com/questions/10679214/how-do-you-set-the-content-type-header-for-an-httpclient-request

@NehaShaikh786 there is no link between your comment/question and the initial question. If you have question on how to do specific things, please post your question to StackOverflow (with all the necessary context and the code you tried)

nrobert avatar Jul 05 '17 15:07 nrobert

@nrobert

Thanks for the response, i know how to call the REST web services in C# and i am able to call it.

My question was.... what will be the BODY parameter for making a POST request.

The only body parameter of the service i know is of Creating Intent Api and it something looks like

{ "Name": "TEST INTENT" }

so what are the parameters APP, UTTERANCE ..... TRAIN and PUBLISH

sayyednazeer avatar Jul 05 '17 15:07 sayyednazeer

Sorry, I thought you were asking for how to call! You're right, the API reference is unclear as it only says {body} for the value like in TRAIN API call Did you try with an empty body? I tested TRAIN with the API testing console and it seems to be working.

For App, Intent, Utterances (see Label) => sample values are in the API reference

nrobert avatar Jul 05 '17 16:07 nrobert

@sayyednazeer for training your model via the authoring API, I took the below snippet from the batch testing portion at the LUIS portal. Have you tried sending the following as the body in a POST request?

[
	{
		"text": "hey dad, are you hungry?",
		"intent": "None",
		"entities": 
		[
		{
			"entity": "FamilyMember",
			"startPos": 4,
			"endPos": 6
		}
		]
	},
	{
		"text": "hey mom, are you hungry?",
		"intent": "None",
		"entities": 
		[
		{
			"entity": "FamilyMember",
			"startPos": 4,
			"endPos": 6
		}
		]
	}
]

stevengum avatar Jul 05 '17 16:07 stevengum

I am seeing the request body in the linked API docs, for example: request body json example - cognitive services apis reference

Create LUIS app - request body:

{
	"name": "MyFirstDummyApp",
	"description": "This is my first dummy application",
	"culture": "en-us",
	"usageScenario": "IoT",
	"domain": "Comics",
	"initialVersionId": "1.0"
}

If there's no request body example for the API call you are looking for, it's probably because there are not a lot of parameters required. For example, to train your app, just use the provided code samples at the bottom.

or use the code examples - cognitive services apis reference

nwhitmont avatar Jul 05 '17 23:07 nwhitmont

@stevengum97

If i want to train application then i think body parameter should only suppose to contains the application id and looking to the sample you have provided it contains the text and intent..!!

Then which text and intent i have to pass all or the newly added...?

sayyednazeer avatar Jul 06 '17 05:07 sayyednazeer

@nwhitmont: the Train sample (your last one) may be the case that is not clear: in the red zone for the cURL sample it says {body} but the request body section above is empty, hence the doubt.

@sayyednazeer: Look at the website, in train section you can train the model (without parameters as you said) but also batch test (as @stevengum97 said). That's 2 different things. For the basic train part as I said yesterday you just have to pass an empty body (try it, you will see training status change on the website)

nrobert avatar Jul 06 '17 06:07 nrobert

@nwhitmont , @stevengum97

I was referring the API version 1.0 Now i have done the same thing with the Version 2.0 and done the testing with the API Console option which they have provided i pass my App id and key and in response it returns 202 accepted but on luis.ai it till shows not trained yet.

Have a look at below snap.

1 2 3

In TRAIN API , if i see the default code, overe there also it show the body parameter

train

sayyednazeer avatar Jul 06 '17 06:07 sayyednazeer

@nrobert

If you see in my above snap, i am testing it with the option "Open Api Testing Console" Over there you can see in the first snap i am passing the request body as an empty.

sayyednazeer avatar Jul 06 '17 06:07 sayyednazeer

I used it yesterday and worked (with an app already trained before), the train date changed after a few seconds. Remember that there is a queue so don't hesitate to wait a bit and force a good refresh of the page

nrobert avatar Jul 06 '17 06:07 nrobert

@nrobert

Still not trained.. :( Can you provide me that javascript sample.. I will try it.

sayyednazeer avatar Jul 06 '17 06:07 sayyednazeer

I wasn't using javascript but the API testing console as you did.

I did a POST and checked again, no change in train date. In fact the train date value in luis.ai website changed only after calling the other method in the train section of the API: GET Get application version training status !

That's not the behaviour I thought it would have.

nrobert avatar Jul 06 '17 07:07 nrobert

@nrobert

Now mine also start working.

What i have done is.... First i have manually train it buy going on the portal.

After that whenever i make a get request , it gets train and not on post. Even i have read somewhere on stack overflow about this training luis works with get and not with post.

Thanks for your help. :)

And do you have any idea about the Publish API In body parameter it was asking accepting the parameter for slack channel also, i have not enable my bot for slack channel so if i remove that parameter it shows error that slack parameter required.

And if add the slack channel and pass any value in slack parameter or blank value it says 404 Bad Request with message Invalid argument. Service response: BadRequest

lol... but the funniest thing is that my application get publish :P

sayyednazeer avatar Jul 06 '17 09:07 sayyednazeer

Sorry I lost you for your last question. You are talking about Publish API for LUIS (this one: https://westus.dev.cognitive.microsoft.com/docs/services/5890b47c39e2bb17b84a55ff/operations/5890b47c39e2bb052c5b9c3b)? I can't see any Slack parameter.

nrobert avatar Jul 06 '17 09:07 nrobert

@nrobert

You are referring the API Version 2.0 It is present in Version 1.0

https://dev.projectoxford.ai/docs/services/56d95961e597ed0f04b76e58/operations/56f8a55119845511c81de482

There are many API's present in Version 1.0 which is not there in V 2.0

Let me check with the Version 2.0

sayyednazeer avatar Jul 06 '17 09:07 sayyednazeer

Oh, okay! But should we still use this v1.0? It was during the project phase... Now methods have been improved and as you said, there's no need to talk about Slack in the publish phase of LUIS, so use 2.0 ;-)

I think that most of the API's method in 1.0 are still in 2.0 but rebranded / refactored. But it would be interesting to get the before/after gap

nrobert avatar Jul 06 '17 09:07 nrobert

yes its working fine with v 2.0.

sayyednazeer avatar Jul 06 '17 09:07 sayyednazeer

@nrobert @nwhitmont

When i create intent with API TESTING CONSOLE (https://dev.projectoxford.ai/docs/services/56d95961e597ed0f04b76e58/operations/56f8a55119845511c81de468/console)

It creates the intent successfully. But when i do it from my javascript it gives me error of BadArgument

SCRIPT

 $('#btnNewIntent').click(function () {
            debugger;
            var intent = $("#txtNewIntent").val();
                var params = {
                    // Request parameters
                };
                debugger;
                $.ajax({
                    url: "https://westus.api.cognitive.microsoft.com/luis/v1.0/prog/apps/{f93134bd-e0b6-4dee-a****9}/intents?" + $.param(params),
                    beforeSend: function (xhrObj) {
                        // Request headers
                        xhrObj.setRequestHeader("Content-Type", "application/json");
                        xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", "045fe2c14f924c59*****e");
                    },
                    type: "POST",
                    // Request body
                    //data: {"Name": "Test"},
                    data: {Name: intent},
                })
                .done(function (data) {
                    debugger;
                    alert("success");
                })
                .fail(function () {
                    debugger;
                    alert("error");
                });
            });

ERROR intenterro

sayyednazeer avatar Jul 09 '17 17:07 sayyednazeer

Did had time to check, but one thing that seems to be wrongly passed:

url: "https://westus.api.cognitive.microsoft.com/luis/v1.0/prog/apps/{f93134bd-e0b6-4dee-add3-85d3f5744a69}/intents?" should not contain { and }, remove them

nrobert avatar Jul 09 '17 17:07 nrobert