Skip to content

Commit c679b56

Browse files
authored
[Components] wit_ai - new components (#16667)
1 parent c5c414f commit c679b56

File tree

8 files changed

+663
-18
lines changed

8 files changed

+663
-18
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import app from "../../wit_ai.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
import constants from "../../common/constants.mjs";
4+
5+
export default {
6+
key: "wit_ai-add-utterance",
7+
name: "Add Utterance",
8+
description: "Add a sample utterance to train your app with an intent. [See the documentation](https://wit.ai/docs/http/20240304#post__utterances).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
text: {
14+
type: "string",
15+
label: "Text",
16+
description: "The text (sentence) you want your app to understand.",
17+
},
18+
outOfScope: {
19+
type: "boolean",
20+
label: "Out of Scope",
21+
description: "To train your app to recognize utterances that it should not handle set this to `true`.",
22+
optional: true,
23+
default: false,
24+
reloadProps: true,
25+
},
26+
},
27+
async additionalProps() {
28+
if (this.outOfScope === true) {
29+
return {};
30+
}
31+
32+
const data = await this.app.listIntents();
33+
const intents = data.map(({ name }) => name);
34+
const intentOptions = intents.concat(Object.values(constants.BUILTIN_INTENTS));
35+
36+
return {
37+
intent: {
38+
type: "string",
39+
label: "Intent",
40+
description: "The name of the intent you wish to create or train.",
41+
options: intentOptions,
42+
},
43+
entities: {
44+
type: "string[]",
45+
label: "Entities",
46+
description: "The list of entities appearing in this sentence, that you want your app to extract once it is trained. Each entity must be a JSON string with the following properties:\n- `entity` (string, required): The entity name, including the role (e.g., `temperature:temperature` or `wit$temperature:temperature`).\n- `start` (integer, required): The starting index within the text.\n- `end` (integer, required): The ending index within the text.\n- `body` (string, required): The span of the text for the entity.\n- `entities` (array, required): List of entities found within the composite entity.\n\nExample: `{\"entity\":\"wit$temperature:temperature\",\"start\":19,\"end\":26,\"body\":\"34 degrees\",\"entities\":[]}`",
47+
optional: true,
48+
},
49+
traits: {
50+
type: "string[]",
51+
label: "Traits",
52+
description: "The list of traits that are relevant for the utterance. Each trait must be a JSON string with the following properties:\n- `trait` (string, required): The trait name. This can be a trait you created, or a built-in one. i.e `faq` or `wit$sentiment`.\n- `value` (string, required): The value for the trait, e.g. `positive`.\n\nExample: `{\"trait\":\"wit$sentiment\",\"value\":\"neutral\"}`",
53+
optional: true,
54+
},
55+
};
56+
},
57+
methods: {
58+
addUtterance(args = {}) {
59+
return this.app.post({
60+
path: "/utterances",
61+
...args,
62+
});
63+
},
64+
},
65+
async run({ $ }) {
66+
const {
67+
addUtterance,
68+
text,
69+
intent,
70+
entities,
71+
traits,
72+
} = this;
73+
74+
const response = await addUtterance({
75+
$,
76+
data: [
77+
{
78+
text,
79+
intent,
80+
entities: utils.parseArray(entities),
81+
traits: utils.parseArray(traits),
82+
},
83+
],
84+
});
85+
86+
$.export("$summary", "Successfully added an utterance to your app.");
87+
return response;
88+
},
89+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../wit_ai.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "wit_ai-create-entity",
6+
name: "Create Entity",
7+
description: "Creates a new entity with the given attributes. [See the documentation](https://wit.ai/docs/http/20240304/#post__entities_link)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
name: {
13+
type: "string",
14+
label: "Name",
15+
description: "Name for the entity. For built-in entities, use the `wit$` prefix.",
16+
},
17+
roles: {
18+
type: "string[]",
19+
label: "Roles",
20+
description: "List of roles you want to create for the entity. A default role will always be created",
21+
optional: true,
22+
},
23+
lookups: {
24+
type: "string[]",
25+
label: "Lookups",
26+
description: "For custom entities, list of lookup strategies (free-text, keywords). Both lookup strategies will be created if empty.",
27+
optional: true,
28+
options: [
29+
"free-text",
30+
"keywords",
31+
],
32+
},
33+
},
34+
methods: {
35+
createEntity(args = {}) {
36+
return this.app.post({
37+
path: "/entities",
38+
...args,
39+
});
40+
},
41+
},
42+
async run({ $ }) {
43+
const {
44+
createEntity,
45+
name,
46+
roles,
47+
lookups,
48+
} = this;
49+
50+
const response = await createEntity({
51+
$,
52+
data: {
53+
name,
54+
roles: utils.parseArray(roles),
55+
lookups: utils.parseArray(lookups),
56+
},
57+
});
58+
59+
$.export("$summary", "Successfully created entity");
60+
61+
return response;
62+
},
63+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import app from "../../wit_ai.app.mjs";
2+
3+
export default {
4+
key: "wit_ai-create-intent",
5+
name: "Create Intent",
6+
description: "Creates a new intent. [See the documentation](https://wit.ai/docs/http/20240304/#post__intents_link)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
type: "string",
13+
label: "Name",
14+
description: "Name for the intent.",
15+
},
16+
},
17+
methods: {
18+
createIntent(args = {}) {
19+
return this.app.post({
20+
path: "/intents",
21+
...args,
22+
});
23+
},
24+
},
25+
async run({ $ }) {
26+
const {
27+
createIntent,
28+
name,
29+
} = this;
30+
const response = await createIntent({
31+
$,
32+
data: {
33+
name,
34+
},
35+
});
36+
$.export("$summary", "Successfully created intent");
37+
return response;
38+
},
39+
};

0 commit comments

Comments
 (0)