How can I take a random input value as a slot variable in Google Actions NLP (google assistant) Console? - google-cloud-platform

Let say I have an app where I want to give someone the weather in a city.
The first scene has a prompt: "What city would you like the weather of?"
I then have to collect a slot/parameter called conv.param.city: and then use it in my node webhook which is:
const { conversation } = require('#assistant/conversation');
const functions = require('firebase-functions');
const app = conversation();
app.handle('schedule', (conv, {location}) => {
let temperature = callApi(location);// this part doesn't matter right now
**conv.add(`You want to know the weather in ${location}`);
conv.close(`The weather in ${location} is ${temperature}`);
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
From what I can tell, you can only take in parameters/slots that are predefined by types/intents. I cannot make a list of all cities that exist to train with. How can I basically say: Whatever the user says at this point, make that word into this variable.
How can i do this with the Google Actions SDK?

You can accomplish this by setting your intent parameter type to be free text (here's an example from one of the sample repos).
freeText: {}
If you apply this type to an intent parameter, you can use the training phrases to provide the necessary context on where in the phrase that "word" should be matched (example from the same repo).
I cannot make a list of all cities that exist to train with.
Another option exists if your API can return the set of locations supported. You can also use runtime type overrides to dynamically generate the type from the list of list of locations the API provides. This will be more accurate, but is dependent on what your data source looks like.

Related

Python Google Prediction example

predict_custom_model_sample(
"projects/794xxx496/locations/us-central1/xxxx/3452xxx524447744",
{ "instance_key_1": "value", ... },
{ "parameter_key_1": "value", ... }
)
Google is giving this example, I am not understanding the parameter_key and instance_key. To my understanding, I need to send the JSON instance.
{"instances": [ {"when": {"price": "1212"}}]}
How can I make it work with the predict_custom_model_sample?
I assume that you are trying this codelab.
Note that there seems to be a mismatch between the function name defined (predict_tabular_model) and the function name used (predict_custom_model_sample).
INSTANCES is an array of one or more JSON values of any type. Each values represents an instance that you are providing a prediction for.
Instant_key_1 is just the first key of the key/value that goes into instances.
Similarly, parameter_key_1 is just the first key of the key/value that goes into the parameters JSON object.
If your model uses a custom container, your input must be formatted as JSON, and there is an additional parameters field that can be used for your container.
PARAMETERS is a JSON object containing any parameters that your container requires to help serve predictions on the instances. AI Platform considers the parameters field optional, so you can design your container to require it, only use it when provided, or ignore it.
Ref.: https://cloud.google.com/ai-platform-unified/docs/predictions/custom-container-requirements#request_requirements
Here you have examples of inputs for online predictions from custom-trained models
For the codelab, I believe you can use the sample provided:
test_instance={
'Time': 80422,
'Amount': 17.99,
…
}
And then call for prediction (Remember to check for the function name in the notebook cell above)
predict_custom_model_sample(
"your-endpoint-str",
test_instance
)

Camunda Modeler Decision Table : Can we source the predefined values (InputValues) for a string input from an external endpoint?

I have an api endpoint which returns a set of values. I want to use these values as a source for predefined values for the input fields in the decision table.
As of now, I can only see the possibility of adding these values as static values in the Modeler. Checked the camunda documentation, could not find anything relevant to this requirement.
Any pointers would be helpful.
You have a few different options to pull values from an external source for use in a decision table. For the purposes of this response, I'll assume your external source is a REST API endpoint. Here are those options:
You could call the decision table from a process definition, and you could source the external values in the process definition prior to the call to the decision table. For example, you could use a Service Task configured as an 'http-connector' to pull the values.
You could expand your decision table such that it becomes a DRD (Decision Requirements Diagram) and utilize a Decision Literal Expression to pull that data.
Finally, you could embed your code to pull data from the external source within a Java bean that is known to the process engine in the current context and call that bean from within your decision table.
I know there's a lot there; if any of it sounds foreign, please review the Camunda documentation at https://docs.camunda.org.
Let me focus on #2 above for a moment and give you a specific example... If you chose that route, your Decision Literal Expression could have the following code within it:
//Get access to the Connectors and Spin Objects.
var Connectors = Java.type('org.camunda.connect.Connectors');
var Spin = Java.type('org.camunda.spin.Spin');
//Create an instance of the HTTP Connector and make the request.
var httpConnector = Connectors.http();
var resp = httpConnector.createRequest()
.post()
.url('http://localhost:1027/creditscore')
.contentType('application/json')
.payload('{"ssn":\"' + ssn + '\"}')
.execute()
.getResponse();
//Retrieve the credit score from the response.
var creditScore = Spin.JSON(resp).prop('creditScore').numberValue();
//Return the credit score, setting it to the variable name specified here.
creditScore;
In that example, I've set the variable name to "creditScore", the type of the variable to "long" and the expression language to "javascript". It requires one variable as input, with that being "ssn". You would be able to use that variable "creditScore" in any decision tables that depend on that decision literal expression in your DRD.

Searching a large data file for a credit card type and its relevant info

So I am running Python 3.7.1 and I am trying to make a program that pulls out only customers that use an American Express card and display only their name and Email.
I have part of the code that pulls all the customers data that uses the same card type, but it pulls up multiple of the same name and email and all other information. I just can't figure out how to eliminate multiples and only display Name and Email. Below I will show a picture of my code and a screen shot of the output for reference.
My code so far
Output(notice the multiples of Mary and Hunter)
Assuming your file isn't extremely long, consider using Python's set data structure to filter out duplicates. You can check for membership within the set via the in operator (e.g. x in s) and you can add new elements to the set via the add() method (e.g. s.add(x)). At a high level, you want to amend your code to check whether the element is already in your set (in which case you don't need to print it again), and if it is not in the set, add it to ensure you don't print it again.

How to give a specific intent response in Amazon Lex based on an earlier response?

I have an initial intent used to classify the user ie Intent1 "I Need help" with a 1 slot (Slot 1) asking "what type of user are you? " The options are "userType1", "UserType2" and UserType3".
following this, with Amazon connect I have a a GetUserInput with multiple inputs. i.e. "What do you need help with?", with lots of intents new intents e.g Intent 2 "Shoes", Intent 3 "socks" Intent 4 "sandals.
Within Intent 2, I want to give a specific text response, Based on the answer to Slot1. the intents are different?
You have to manage context of the conversation to be able to take actions based on previous responses.
https://docs.aws.amazon.com/lex/latest/dg/context-mgmt.html
Basically in the first intent, based on the slot value you have to store it in session attributes, in the next intent you will check the value and generate the response.
Do check the OrderFlowers Blueprint Lambda function and this link. Notice that once the user gives the slot value of FlowerType it sets the price as session attribute.
Hope it helps, let me know if you have further doubts

Is there a table which holds all possible states of a determined work Item type in TFS?

I'm developing a Time Tracking system in TFS so we can control how much time is spent in each task. I'm doing it by checking changes in work items states, and recording the time between states.
I'm using WCF and TFS2010 alert subscription.
Then I noticed the State column in the WorkItem table holds a string, instead of an ID pointing to a State.
With that in mind, I noticed I would have to parse each state and check if it corresponds to some string. And then, some day, someone might want to change the State name. Then we're doomed.
But before I hardcore (or put in some random config.xml)... let me ask, is there a table which holds all possible states of a determined work Item type in TFS?
The states of work item types are stored in the process template files. You can export the work item type to an xml file using witadmin.exe and see the allowed values of the "State" in there.
Programmatically, you can use the Microsoft.TeamFoundation.WorkItemTracking.Client namespace to get the WorkItemType object of your work item type, look for the FieldDefinition object of the "State" in the FieldDefinitions property, then get the possible states from the AllowedValues property of FieldDefinition class.