How to get prompts from Question Answering .NET - microsoft-cognitive

i'm struggling with Language studio question answering, as QnA maker it will be deprecated i decided to move to language studio, now i get answer from my KB but im not able to get all propts like QnA maker do: with QnA make this code snippets works fine but for Qustion answering not.
foreach (QnaMakerPrompt qnaMakerPrompt in queryResult.Context.Prompts)
{
message = $"{qnaMakerPrompt.DisplayOrder} - {qnaMakerPrompt.DisplayText}";
card.Actions.Add(new AdaptiveSubmitAction()
{
Title = message,
Data = qnaMakerPrompt.DisplayText,
});
}
I found this class that I think is right for me but it doesnt work
https://learn.microsoft.com/en-us/dotnet/api/azure.ai.language.questionanswering.knowledgebaseanswerprompt?view=azure-dotnet#applies-to
this is what i've done i get response from my KB but not showing all the promps
Uri endpoint = new Uri("URL");
AzureKeyCredential credential = new AzureKeyCredential("KEY");
QuestionAnsweringClient client = new QuestionAnsweringClient(endpoint, credential);
string projectName = "STRING";
string deploymentName = "test";
QuestionAnsweringProject project = new QuestionAnsweringProject(projectName, deploymentName);
Response<AnswersResult> response = await client.GetAnswersAsync("String", project);
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
{
await turnContext.SendActivityAsync(MessageFactory.Text(answer.Answer.ToString(), answer.Answer.ToString()), cancellationToken);
}
Hope someone can help me, thank you a lot

Related

Simple Odata Client to consume Odata with Authentication not working

I m new to Simple.Odata.client. I had a problem to access the Odata Service with below code. The below code return null. but Postman return with result.
suspected Problem : How to pass a url string with '1000' &format=json
Is the below Simple odata client setup correctly?
There is no UrlBase in Simple Odata client, but there is BAseUri
Is this ODataClientSettings working??
var settings = new Simple.OData.Client.ODataClientSettings();
settings.BaseUri = new Uri("https://..../UoM?$filter=wer eg '1000' &format=json");
settings.Credentials = new NetworkCredential("user1", "usrpwd");
var client = new ODataClient(settings);
please help
Thanks
This worked for me
var credentials = new NetworkCredential(userName, password); //you can use the override with the domain too.
var settings = new ODataClientSettings(baseUrl, credentials) //baseUrl is a string.
{
IgnoreResourceNotFoundException = true,
OnTrace = (x, y) => Debug.WriteLine(x, y),
PayloadFormat = ODataPayloadFormat.Json, //here is where you specify the format
IgnoreUnmappedProperties = true,
RenewHttpConnection = true,
TraceFilter = ODataTrace.All,
PreferredUpdateMethod = ODataUpdateMethod.Merge
};
var client = new ODataClient(settings);
Your baseUrl should not contain all those OData tags but the endpoint of your service like https://myservice.mysite.com/api.svc. Then as you use the Simple.OData.Client the resource url will be automatically completed.
Please, take a look at the OData standard to figure out how it works and see the Simple.OData.Client repo's examples to better understand how to use it.
To better understand how to use the Windows Authentication you can check Authentication and Authorization with Windows Accounts and how to access website with Windows credential
Hope this help.

How do I do an EF Database.ExecuteSQLCommand async?

Here's the code that I am using:
public async Task<IHttpActionResult> NewTopicTests([FromBody] NewTopicTestsDTO testSpec)
{
var sql = #"dbo.sp_new_topic_tests #Chunk";
SqlParameter[] parameters = new SqlParameter[]
{
new SqlParameter("#Chunk", testSpec.Chunk)
};
int result = db.Database.ExecuteSqlCommand(sql, parameters);
await db.SaveChangesAsync();
return Ok();
}
Can someone confirm if this is the correct way to do this using async? In particular do I need to do this:
int result = db.Database.ExecuteSqlCommand(sql, parameters);
await db.SaveChangesAsync();
Note that the code works however I am having a problem with my application where it suddenly stops without any error message. I am looking into every possible problem.
What's being saved here ? I think there is no need to call save changes here.
Remove save changes and you will see the same behavior, because any changes you've made in your stored procedure, are not tracked by entity framework context.
And you can rewrite your code as following:
int result = await db.Database.ExecuteSqlCommandAsync(sql, parameters);
Have you checked every where to find the reason of your problem ? Windows Error Log etc ?
Go to Debug menu of Visual Studio IDE, and open Exceptions, then check both 'throw' and 'user_unhandled' for 'Common Language Runtime Exceptions' and test your code again.

Updating Calendar Event Giving Error "The specified value is not a valid quoted string"

As of today we are getting an error when we try to update an event using Google Calendar V3 API.
Here is our code:
string certificateFile = getCertificateFile();
string certificatePassword = getCertificatePassword();
string serviceAccountEmail = getServiceAccountEmail();
X509Certificate2 certificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certs//" + certificateFile, certificatePassword, X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { Google.Apis.Calendar.v3.CalendarService.Scope.Calendar },
User = user
}.FromCertificate(certificate));
Google.Apis.Calendar.v3.CalendarService service = new Google.Apis.Calendar.v3.CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Test",
});
try
{
Event evv = service.Events.Get(user, "6ebr4dp452m453n468movuntag").Execute();
EventsResource.UpdateRequest ur = new EventsResource.UpdateRequest(service, evv, user, evv.Id);
ur.Execute();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
The Error message is " The specified value is not a valid quoted string. "
This is basic code that always works. We can still query and insert Events. For some reason updates have just stopped working?
Anybody else getting this?
I found what is the problem: Google API's ETag functionality seems to be broken.
To get around the issue I had to download the source code of the .NET Google API client libraries from google-api-dotnet-client Downloads and commented the call to the method AddETag() on line 189 of ClientServiceRequest.cs; that method adds the If-Match ETag header that's currently causing the issues. This file is in the GoogleApis project.
public HttpRequestMessage CreateRequest(Nullable<bool> overrideGZipEnabled = null)
{
var builder = CreateBuilder();
var request = builder.CreateRequest();
object body = GetBody();
request.SetRequestSerailizedContent(service, body, overrideGZipEnabled.HasValue
? overrideGZipEnabled.Value : service.GZipEnabled);
//AddETag(request);
return request;
}
See Protocol Reference: Updating Entries for more information on how Google API's use ETags and the If-Match header.
The problem in the Calendar API was fixed so no need to use this workaround!
Please don't use the above suggestion. Although it works, it will actually eliminate an important feature of etag in the library. A better solution is available at: https://codereview.appspot.com/96320045/
Thanks diegog for your work-around, I'm pretty sure it helped several users who were stuck today.

FileReference.upload non asynchronous?

I'm a bit of a flex noob, but I couldn't find this question asked anywhere, or a proper workaround. I'm quite used to GET/POST and web interactions, but I'm new to working in mxml's and such. See function below.
private function uploadFileSelect(event:Event):void
{
var uploadURL:String = Application.application.parameters.UploadURL;
var urlStr:String = ExternalInterface.call('window.location.href.toString');
var queryMap:Object = getQueryParams(urlStr);
var request:URLRequest = new URLRequest(uploadURL);
var urlVars:URLVariables = new URLVariables();
urlVars.appid = queryMap.appid;
urlVars.str = queryMap.str;
request.method = "POST";
request.data = urlVars;
uploadFileRef.upload(request);
}
Essentially, this works perfectly for what I need, with one exception. The final call to .upload is asynchronous, so I stay on the current page, but it calls the upload URL in the background. I want it to act like a form and actually navigate TO the upload URL with the POST data. I feel like this should be a simple solution, but I was kind of thrown the task of working on someone else's flash code and need a little advice.
Thanks in advance!
Because it is asynchronous, you cannot achieve redirect from the UI like you do in Html form. As a work around you can add listeners to the uploadFileRef
uploadURL = "someurl";
uploadFileRef.addEventListener(Event.complete, function(e:Event){
navigateToURL(new URLRequest(uploadURL),'_self')
});
navigate url will tke you to the target url. I do not know how you will get the uploadURL, i'm assuming it is the url at which you have uploaded the file to.

Google Apps Admin Settings API - 401

I'm trying to get the Organization name for a Google Apps domain. For this, I'm using the Google Apps Admin Settings API. I saw that it required 3-Legged OAuth. I try to implement OAuth 2.0 because OAuth 1 is deprecated. I try many thing to get this work but I'm always getting a 401 unautorized.
I request a token for the scope : https://apps-apis.google.com/a/feeds/domain/
Here is my code:
// ClientID & ClientSecret values
var requestFactory = GDAPI.GoogleApps.GetAuthRequestFactory();
string organizationName = String.Empty;
Google.GData.Apps.AdminSettings.AdminSettingsService service =
new Google.GData.Apps.AdminSettings.AdminSettingsService(auth.Domain, Excendia.Mobility.Utilities1.BLL.WebConfig.ExcendiaAppName);
service.RequestFactory = requestFactory;
service.SetAuthenticationToken(token);
try
{
var result = service.GetOrganizationName(); // throw exception here...
}
catch (Exception ex)
{
log.Error(ex);
}
What am I doing wrong?
Is this compatible with OAuth 2?
I also want to ask if there is another way to get organization name because GData library is supposed to be obsolete and replaced by new Google.Apis...
Resolved!
Thanks Jay. It works on OAuth 2.0 playground. Something on my side was not set correctly.
Using Fiddler I saw the Authorization header being set by my application. It was set to OAuth v1 instead of v2. So I found out I was using the wrong RequestFactory class.
Need to use GOAuth2RequestFactory instead of GOAuthRequestFactory...
So this is now working:
string organizationName = String.Empty;
Google.GData.Apps.AdminSettings.AdminSettingsService service =
new Google.GData.Apps.AdminSettings.AdminSettingsService(auth.Domain, "myAppName");
service.RequestFactory =
new Google.GData.Client.GOAuth2RequestFactory("cl", "MyAppName",
new Google.GData.Client.OAuth2Parameters()
{ ClientId = ClientID,
ClientSecret = ClientSecret,
AccessToken = token });
try
{
var result = service.GetOrganizationName();
if (result != null)
{
organizationName = result.OrganizationName;
}
}
catch (Exception ex)
{
log.Error(ex);
}
return organizationName;
You are using the correct API. Though GData is being replaced by the new Google APIs, Admin Settings API still uses the old GData format for now.
Are you using a super administrator account to authenticate with? Can you try the operation on the OAuth 2.0 playground and see if it works for the account there?
You can also take a look at how Dito GAM, an open source Google Apps tool implements this call. If you create a file named debug.gam in the same path as GAM, GAM will print out all the raw HTTP calls and responses it's making/getting.

Resources