Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove excess rule fetching on /training/intents page #754

Merged
merged 45 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6316b3b
Merge relevant from old branch
IgorKrupenja Dec 3, 2024
47d942c
Fix guard
IgorKrupenja Dec 3, 2024
b10dc8d
Fix response logic
IgorKrupenja Dec 3, 2024
37dfc75
Fix deps
IgorKrupenja Dec 3, 2024
06ecd85
Remove deupe code
IgorKrupenja Dec 3, 2024
5f6230e
TODOs
IgorKrupenja Dec 3, 2024
2340c4c
Revert unrelated changes
IgorKrupenja Dec 3, 2024
26f57fc
Clean up
IgorKrupenja Dec 3, 2024
c9750b9
Clean up
IgorKrupenja Dec 3, 2024
9f73066
Clean up
IgorKrupenja Dec 3, 2024
e916819
Fix deletion
IgorKrupenja Dec 3, 2024
b73c29f
Clean up
IgorKrupenja Dec 3, 2024
6e6b23e
Move entities
IgorKrupenja Dec 3, 2024
4faea19
Clean up
IgorKrupenja Dec 3, 2024
3ebaaf8
Clean up
IgorKrupenja Dec 3, 2024
f1fefc2
Fix adding example
IgorKrupenja Dec 3, 2024
df075da
Fix examples
IgorKrupenja Dec 3, 2024
ec52131
Clean up
IgorKrupenja Dec 3, 2024
048941e
Clean up
IgorKrupenja Dec 3, 2024
4596ee3
Clean up
IgorKrupenja Dec 3, 2024
802eed2
Fix rule
IgorKrupenja Dec 4, 2024
efad763
Fix editing example
IgorKrupenja Dec 4, 2024
4b4bd07
gsa
IgorKrupenja Dec 4, 2024
8786af7
Clean up
IgorKrupenja Dec 4, 2024
f785f2f
Clean up
IgorKrupenja Dec 4, 2024
5a11419
Clean up
IgorKrupenja Dec 4, 2024
871fc7d
Fix the issue
IgorKrupenja Dec 5, 2024
ef68b39
PoC without data mapping
IgorKrupenja Dec 6, 2024
705cb8f
PoC with poor format
IgorKrupenja Dec 6, 2024
9fa9066
PoC with better format
IgorKrupenja Dec 6, 2024
8e97646
Clean up
IgorKrupenja Dec 6, 2024
96153ef
Cle
IgorKrupenja Dec 6, 2024
c41897e
PoC component
IgorKrupenja Dec 6, 2024
3d770c8
Clean up
IgorKrupenja Dec 6, 2024
fe8ce3f
Fix name
IgorKrupenja Dec 6, 2024
3c154c6
Fix query
IgorKrupenja Dec 6, 2024
265107c
Fix fetch
IgorKrupenja Dec 6, 2024
5def279
Revert unrelated changes
IgorKrupenja Dec 6, 2024
6921388
Clean up
IgorKrupenja Dec 6, 2024
4e33c26
Clean up
IgorKrupenja Dec 6, 2024
52534ec
Clean up
IgorKrupenja Dec 9, 2024
746588b
Clean up
IgorKrupenja Dec 10, 2024
b8b60ec
PoC request
IgorKrupenja Dec 10, 2024
c44fcd0
Finish
IgorKrupenja Dec 10, 2024
f1556dc
Merge base
IgorKrupenja Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
{
}
"[typescript][typescriptreact][json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
12 changes: 12 additions & 0 deletions DSL/DMapper/hbs/get_intent_by_id.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "{{intents.intents.0._source.id}}",
"examples": [
{{#each intents.intents.0._source.examples}}
"{{{this}}}"{{#unless @last}},{{/unless}}
{{/each}}
],
"inModel": {{isInModel intents.intents.0._source.intent intents}},
"serviceId": "{{findConnectedServiceId intents.intents.0._source.intent intents}}",
"isForService": "{{getObjectKeyFromObjectArray intents/intentsModifiedAt 'intent' intents.intents.0._source.intent 'isforservice'}}",
"modifiedAt": "{{intents.intentsModifiedAt.0.created}}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"intents": [
{{#each hits}}
"{{key}}"{{#unless @last}},{{/unless}}
{{/each}}
]
}
2 changes: 1 addition & 1 deletion DSL/DMapper/hbs/get_intents_with_examples.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"intents": [
{{#each hits}}
{
"id": "{{_source._id}}",
"id": "{{_id}}",
"title": "{{_source.intent}}",
"examples": [
{{#each _source.examples}}
Expand Down
6 changes: 4 additions & 2 deletions DSL/DMapper/hbs/get_intents_with_examples_count.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"intents": [
{{#each buckets}}
{
"intent": "{{key}}",
"examples_count": {{examples_counts.value}}
"id": "{{key}}",
"examples_count": {{examples_counts.value}},
"inModel": {{isInModel key ../intents}},
"modifiedAt": "{{findModifiedAt key ../intents/intentsModifiedAt}}"
}{{#unless @last}},{{/unless}}
{{/each}}
]
Expand Down
6 changes: 6 additions & 0 deletions DSL/DMapper/hbs/get_response_by_intent_id.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"response": {
"name": "{{response.0._id}}",
"text": {{#if response.0._source.response.[0].condition}}"{{{response.0._source.response.[1].text}}}"{{else}}"{{{response.0._source.response.[0].text}}}"{{/if}}
}
}
3 changes: 3 additions & 0 deletions DSL/DMapper/hbs/get_rule_by_intent_id.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"id": "{{hits.0._source.rule}}"
}
23 changes: 11 additions & 12 deletions DSL/OpenSearch/templates/intents-with-examples-count.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,31 @@
"aggs": {
"hot": {
"terms": {
"field": "intent.keyword"
"field": "intent",
"size": 10000
},
"aggs": {
"examples_counts": {
"value_count": {
"field": "examples.raw"
"field": "examples"
}
}
}
}
},
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "*{{intent}}*",
"default_field": "intent"
}
}
]
{{#intent}}
"wildcard": {
"intent": "*{{intent}}*"
}
{{/intent}}
{{^intent}}
"match_all": {}
{{/intent}}
}
},
"params": {
"intent": ""
}
}
}
}
6 changes: 4 additions & 2 deletions DSL/OpenSearch/templates/response-with-name-and-text.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"query": "*{{response_name}}*",
"default_field": "name"
}
},
}
{{#response_text}},
{
"query_string": {
"query": "*{{response_text}}*",
"default_field": "response.text"
}
}
{{/response_text}}
]
}
}
Expand All @@ -27,4 +29,4 @@
"response_text": ""
}
}
}
}
4 changes: 2 additions & 2 deletions DSL/Ruuter.private/GET/.guard
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ process_request:
verify_header_nonce:
call: http.post
args:
url: [#TRAINING_RESQL]/use-nonce
url: "[#TRAINING_RESQL]/use-nonce"
body:
updated_nonce: ${incoming.headers['x-ruuter-nonce']}
result: nonce_response
Expand All @@ -18,7 +18,7 @@ verify_header_nonce:
verify_param_nonce:
call: http.post
args:
url: [#TRAINING_RESQL]/use-nonce
url: "[#TRAINING_RESQL]/use-nonce"
body:
updated_nonce: ${incoming.params['ruuter-nonce']}
result: nonce_response
Expand Down
89 changes: 89 additions & 0 deletions DSL/Ruuter.private/GET/rasa/intents/by-id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
declaration:
call: declare
version: 0.1
description: "Get intent with details by ID"
method: get
accepts: json
returns: json
namespace: training
allowlist:
headers:
- field: cookie
type: string
description: "Cookie field"
params:
- field: intent
type: string
description: "Intent ID"

assignValues:
assign:
intent: ${incoming.params.intent}

getIntent:
call: http.post
args:
url: "[#TRAINING_OPENSEARCH]/intents/_search/template"
body:
id: "intent-with-name"
params:
intent: ${intent}
result: getIntentResult

getDomainFile:
call: http.get
args:
url: "[#TRAINING_PUBLIC_RUUTER]/internal/domain-file"
headers:
cookie: ${incoming.headers.cookie}
result: getDomainDataResult

checkIfIntentExists:
switch:
- condition: ${getIntentResult.response.body.hits.hits != null}
next: getServiceIntentConnections
next: returnNoIntentFound

getServiceIntentConnections:
call: http.post
args:
url: "[#TRAINING_RESQL]/get-service-intent-connections"
result: getServiceIntentConnectionsResult

getIntentListLastChanged:
call: http.post
args:
url: "[#TRAINING_RESQL]/get-intents-list-last-changed"
body:
intentsList: ${getIntentResult.response.body.hits.hits[0]._id}
result: getIntentListLastChangedResult

assignResults:
assign:
# TODO: Ideally, should use a single object, not array
intents:
intents: ${getIntentResult.response.body.hits.hits}
inmodel: ${getDomainDataResult.response.body.response.intents}
connections: ${getServiceIntentConnectionsResult.response.body}
intentsModifiedAt: ${getIntentListLastChangedResult.response.body}

mapIntentData:
call: http.post
args:
url: "[#TRAINING_DMAPPER]/hbs/training/get_intent_by_id"
headers:
type: "json"
body:
intents: ${intents}
result: getIntentDataResult
next: returnSuccess

returnSuccess:
return: ${getIntentDataResult.response.body}
next: end

returnNoIntentFound:
return: "Error: no intent found"
wrapper: false
status: 404
next: end
33 changes: 0 additions & 33 deletions DSL/Ruuter.private/GET/rasa/intents/examples/count.yml

This file was deleted.

65 changes: 65 additions & 0 deletions DSL/Ruuter.private/GET/rasa/intents/with-examples-count.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
declaration:
call: declare
version: 0.1
description: "Decription placeholder for 'COUNT'"
method: get
accepts: json
returns: json
namespace: training
allowlist:
headers:
- field: cookie
type: string
description: "Cookie field"

getIntentsExampleCount:
call: http.post
args:
url: "[#TRAINING_OPENSEARCH]/intents/_search/template"
body:
id: "intents-with-examples-count"
result: getIntentsResult

getDomainFile:
call: http.get
args:
url: "[#TRAINING_PUBLIC_RUUTER]/internal/domain-file"
headers:
cookie: ${incoming.headers.cookie}
result: getDomainDataResult

getIntentsNames:
call: http.post
args:
url: "[#TRAINING_DMAPPER]/hbs/training/get_intent_names_from_example_counts"
headers:
type: "json"
body:
hits: ${getIntentsResult.response.body.aggregations.hot.buckets}
result: getIntentsNamesResult

getIntentListLastChanged:
call: http.post
args:
url: "[#TRAINING_RESQL]/get-intents-list-last-changed"
body:
intentsList: ${getIntentsNamesResult.response.body.intents}
result: getIntentsListLastChangedResult

mapIntentsData:
call: http.post
args:
url: "[#TRAINING_DMAPPER]/hbs/training/get_intents_with_examples_count"
headers:
type: "json"
body:
buckets: ${getIntentsResult.response.body.aggregations.hot.buckets}
intents:
inmodel: ${getDomainDataResult.response.body.response.intents}
intentsModifiedAt: ${getIntentsListLastChangedResult.response.body}
result: intentsData
next: returnSuccess

returnSuccess:
return: ${intentsData.response.body}
next: end
42 changes: 42 additions & 0 deletions DSL/Ruuter.private/GET/rasa/response-by-intent-id.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
declaration:
call: declare
version: 0.1
description: "Get response by intent name"
method: get
accepts: json
returns: json
namespace: training
allowlist:
params:
- field: intent
type: string
description: "Intent ID"

assign_values:
assign:
response_name: ${"utter_" + incoming.params.intent}

getResponsesWithNameAndText:
call: http.post
args:
url: "[#TRAINING_OPENSEARCH]/responses/_search/template"
body:
id: "response-with-name-and-text"
params:
response_name: ${response_name}
result: getResponsesResult

mapResponsesData:
call: http.post
args:
url: "[#TRAINING_DMAPPER]/hbs/training/get_response_by_intent_id"
headers:
type: "json"
body:
response: ${getResponsesResult.response.body.hits.hits}
result: responsesData
next: returnSuccess

returnSuccess:
return: ${responsesData.response.body.response}
next: end
2 changes: 1 addition & 1 deletion DSL/Ruuter.private/GET/rasa/responses-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mapResponsesData:
args:
url: "[#TRAINING_DMAPPER]/hbs/training/get_responses_list"
headers:
type: 'json'
type: "json"
body:
response: ${getResponsesResult.response.body.hits.hits}
result: responsesData
Expand Down
Loading