Is it possible to set the value of a context variable based on a set of conditions which depend on value of another context value? I am trying to integrate NLU(Natural Language Understanding) service with Conversation service and would like to set some context variables based on the values returned by NLU. For example I am getting following entities from NLU:
{
...
"context": {
...
"nlu_response": {
"entities": [{
"type": "Person",
"relevance": 0.5,
"count": 1,
"text": "Jon Doe",
"emotion": {
"anger": 0.082378,
"disgust": 0.033499,
"fear": 0.072588,
"joy": 0.100971,
"sadness": 0.147584
},
"sentiment": {
"score": 0.409803
}
},
{
"type": "Person",
"relevance": 0.5,
"count": 1,
"text": "Jane Doe",
"emotion": {
"anger": 0.140151,
"disgust": 0.091598,
"fear": 0.059244,
"joy": 0.046762,
"sadness": 0.165763
},
"sentiment": {
"score": 0
}
}]
}
}
}
and would like to create a context variable EntityPerson_1 with a value of "Jon Doe" only if there are values in entity object with type="Person".
In other words is something like this possible in a response node:
{
...
"context": {
...
"EntityPerson_1": <? context.nlu_response.entities.size()>0 && context.nlu_response.entities.get(0).type.contains('Person')?context.nlu_response.entities.get(0).text:'' ?>
}
}
Yes, it is possible. Your code is almost correct. Working code is:
{
...
"context": {
...
"EntityPerson_1": "<? context.nlu_response.entities.size()>0 && context.nlu_response.entities.get(0).type.contains('Person')?context.nlu_response.entities.get(0).text:'' ?>"
}
Related
I am trying to deploy a App service webapp via ARM template and need to put a secret from a key vault into an app setting (env variable).
I have always simply used an array of values from a parameters file to populate these app settings, but now I am struggling to get a keyvault value into that array. Something like shown below in an ARM parameter file.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"someStringParam": {
"value": "stringLiteralValueHere"
},
"envVars": {
"value": [
{
"name": "envVarKeyName",
"value": "stringLiteralValueHere"
},
{
"name": "KVsecret1",
"value": ##KEY VAULT SECRET HERE##
}
]
}
}
}
I have tried using a reference to the keyvault for the value but that errors on deployment.
{
"name": "KVsecret1",
"reference": {
"keyVault": {
"id": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.KeyVault/vaults/<vault_name>"
},
"secretName": "secret1"
}
}
I have also tried using a parameter inside of the parameter file, but that just used the literal string for the value.
"parameters": {
"KVsecret1": {
"reference": {
"keyVault": {
"id": "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.KeyVault/vaults/<vault_name>"
},
"secretName": "KVsecret1"
}
},
"envVars": {
"value": [
{
"name": "envVarKeyName",
"value": "stringLiteralValueHere"
},
{
"name": "KVsecret1",
"value": "[parameters('KVsecret1')]"
}
]
}
}
Is this possible??
EDIT: Adding some detail here.
I am also trying to shoe horn a reference to another resource to get put the app insights instrumentation key into an app setting. Below is what I would like to do, but the copy function needs to use the name of the property and that is dynamic in this case as it changes with the each member of the array from the parameter file.
{
"type": "Microsoft.Web/sites/config",
"apiVersion": "2022-03-01",
"name": "[concat(parameters('backEndwebAppName'),'/appsettings')]",
"kind": "string",
"properties": {
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(concat('microsoft.insights/components/',parameters('appInsightsName')),'2020-02-02').InstrumentationKey]",
"secret1FromKeyvault": "[parameters('secret1FromKeyvault')]",
"copy": [
{
"name": "envVarsFromParams",
"count": "[length(parameters('backEndEnvVariables'))]",
"input": {
"name": "[parameters('backEndEnvVariables')[copyIndex('envVarsFromParams').name]]",
"value": "[parameters('backEndEnvVariables')[copyIndex('envVarsFromParams').value]]"
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('backEndwebAppName'))]"
]
},
This isn't possible today within the param file, but in your scenario (if it's as simple as your OP example) you can just union the two in your template. So in your parameter file, you have 2 params kvSecret (the reference) and envVars (all your other env vars) and then in the template use:
"variables": {
"keySecretObj": {
"name": "kvSecret",
"value": "[parameters('kvSecret')]"
},
"envVarsFinal": "[union(parameters(variables('kvSecretObj`), parameters(`envVars`))]"
That help?
I have a query:
query SearchProductData($tagId: [Int!]) {
product(where: { productTags: {_or: {tagId: {_in: $tagId}}}}) {
id
name
productTags {
tag {
id
name
}
}
}
}
and I pass in a variable of
{"tagId": null}
I would like to get back all product, regardless of if they have tags applied or not. What happens though is it retrieves only items with tags applied, not including the items with no tags.
the DB schema is
|- product
|
|-- productTags (one to many linking table of productIDs and tagIDs)
|
|--- tags
Any ideas how to write a query for this use case?
This is expected because of how the where clause is translating to a join (you can see the Generated SQL and Execution Plan query analysis by clicking Analyze in GraphiQL console.)
I don't think it's possible without injecting a bool expression. See below:
E.g.
query Test($expression: product_bool_exp) {
product(where: $expression) {
id
name
product_tags {
tag {
id
name
}
}
}
}
with argument
{
"expression": {"product_tags": {"tag_id": {"_in": [2]}}}
}
returns back:
{
"data": {
"product": [
{
"id": 1,
"name": "product_A",
"product_tags": [
{
"tag": {
"id": 1,
"name": "tag_1"
}
},
{
"tag": {
"id": 2,
"name": "tag_2"
}
}
]
}
]
}
}
And for the other case using the same query (where there are no tags passed in, and therefore all products we can use this variable value:
{
"expression": null
}
And we get back...
{
"data": {
"product": [
{
"id": 1,
"name": "product_A",
"product_tags": [
{
"tag": {
"id": 1,
"name": "tag_1"
}
},
{
"tag": {
"id": 2,
"name": "tag_2"
}
}
]
},
{
"id": 4,
"name": "product_D",
"product_tags": []
}
]
}
}
So you can dynamically construct that where expressions and pass that as an argument to the query.
I'm currently doing some tests on google datastore, but I'm having a problem with my queries.
If I believe in the documentation https://cloud.google.com/datastore/docs/concepts/queries we can realize a filter on several columns with the instruction EQUALS.
But when testing, I get an error from the API.
While searching on Datastore's github, I found this reference: https://github.com/GoogleCloudPlatform/google-cloud-dotnet/issues/304 which corresponds to my problem, except that for my case the query to the look good.
Here is the request sent:
{
{
"kind": [{
"name": "talk.message"
}],
"filter": {
"compositeFilter": {
"op": "AND",
"filters": [{
"propertyFilter": {
"property": {
"name": "Conversation"
},
"op": "EQUAL",
"value": {
"stringValue": "2f16c14f6939464ea687d316438ad4cb"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "LESS_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-15T10:43:31.474166300Z"
}
}
},
{
"propertyFilter": {
"property": {
"name": "CreatedOn"
},
"op": "GREATER_THAN_OR_EQUAL",
"value": {
"timestampValue": "2019-03-14T10:43:31.474175100Z"
}
}
}
]
}
}
}
}
And here is the answer from the API:
{Grpc.Core.RpcException: Status(
StatusCode=FailedPrecondition,
Detail="no matching index found. recommended index is:
- kind: talk.message
properties:
- name: Conversation
- name: CreatedOn"
)
According to the documentation, this should be good... but it's not !
What am I missing ?
Your query includes both an EQUALS (on Conversation) and a non-EQUALS filter (on CreatedOn), therefore you need a composite index to fulfil the query. So your query is valid, but it needs a composite index to be able to run the query.
I'm working with Watson Conversation, inside a dialog.
I want to return all values of one entity in an array context variables.
The following works
{
"context": {
"toppings_array":["#toppings[0]","#toppings[1]"] works.
...
}
I'd like to find a generic solution, such as
{
"context": {
"toppings_array":["#toppings"]
...
}
The above sample sets the toppings_array value to the first element of the entity (e.g. #toppings[0]).
Thx.
You can do the following:
{
"context": {
"toppings_array": "<? entities['toppings'] ?>"
...
}
You would end up with something like:
[
{
"entity": "toppings",
"location": [
4,
13
],
"value": "pepperoni",
"confidence": 1
},
{
"entity": "toppings",
"location": [
14,
23
],
"value": "sprinkles",
"confidence": 1
}
]
Just Use # Topping.values . It will return all the values in form of array in context variable.
I have an endpoint setup on API gateway that is talking directly to DynamoDB.
As a post request comes in I use the body mapper script to map my url request parameters to dynamoDB params.
My URL params
{
"name": "sdaf",
"location": "asdf",
"gender": "male"
}
Body Mapper Script
{
"TableName": "sample-table",
"Item": {
"firstName": {
"S": "$input.path('$.name')"
},
"location": {
"S": "$input.path('$.location')"
}
}
}
All of this works fine until I have to write a whole object to dynamo.
New URL Params
{
"name": "sdaf",
"location": "asdf",
"gender": "male",
"hobbies": {
"hobby1": {
"startedAt": "<some time>"
},
"hobby2": {
"startedAt": "<some time>"
},
}
}
I am not sure how the body mapper is supposed to look like for this situation?
I have tried this:
Body Mapper
{
"TableName": "sample-table",
"Item": {
"firstName": {
"S": "$input.path('$.name')"
},
"location": {
"S": "$input.path('$.location')"
},
"hobbies": {
"M": "$input.path('$.hobbies')"
}
}
}
But doesn't work. I wonder if there is a way to dump an object into a column in dynamo from the api gateway directly. I know this is possible with adding a lambda in between but I want to avoid that.
I don't think this can be made to work while passing hobbies as a URL parameter.
If you instead pass hobbies in the body, you can do something like this:
"M": {
#foreach( $elem in $input.path('$.hobbies'))
$elem
#if($foreach.hasNext),#end
#end
}