Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
89 changes: 89 additions & 0 deletions components/wit_ai/actions/add-utterance/add-utterance.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import app from "../../wit_ai.app.mjs";
import utils from "../../common/utils.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "wit_ai-add-utterance",
name: "Add Utterance",
description: "Add a sample utterance to train your app with an intent. [See the documentation](https://wit.ai/docs/http/20240304#post__utterances).",
version: "0.0.1",
type: "action",
props: {
app,
text: {
type: "string",
label: "Text",
description: "The text (sentence) you want your app to understand.",
},
outOfScope: {
type: "boolean",
label: "Out of Scope",
description: "To train your app to recognize utterances that it should not handle set this to `true`.",
optional: true,
default: false,
reloadProps: true,
},
},
async additionalProps() {
if (this.outOfScope === true) {
return {};
}

const data = await this.app.listIntents();
const intents = data.map(({ name }) => name);
const intentOptions = intents.concat(Object.values(constants.BUILTIN_INTENTS));

return {
intent: {
type: "string",
label: "Intent",
description: "The name of the intent you wish to create or train.",
options: intentOptions,
},
entities: {
type: "string[]",
label: "Entities",
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\":[]}`",
optional: true,
},
traits: {
type: "string[]",
label: "Traits",
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\"}`",
optional: true,
},
};
},
methods: {
addUtterance(args = {}) {
return this.app.post({
path: "/utterances",
...args,
});
},
},
async run({ $ }) {
const {
addUtterance,
text,
intent,
entities,
traits,
} = this;

const response = await addUtterance({
$,
data: [
{
text,
intent,
entities: utils.parseArray(entities),
traits: utils.parseArray(traits),
},
],
});

$.export("$summary", "Successfully added an utterance to your app.");
return response;
},
};
63 changes: 63 additions & 0 deletions components/wit_ai/actions/create-entity/create-entity.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import app from "../../wit_ai.app.mjs";
import utils from "../../common/utils.mjs";

export default {
key: "wit_ai-create-entity",
name: "Create Entity",
description: "Creates a new entity with the given attributes. [See the documentation](https://wit.ai/docs/http/20240304/#post__entities_link)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
type: "string",
label: "Name",
description: "Name for the entity. For built-in entities, use the `wit$` prefix.",
},
roles: {
type: "string[]",
label: "Roles",
description: "List of roles you want to create for the entity. A default role will always be created",
optional: true,
},
lookups: {
type: "string[]",
label: "Lookups",
description: "For custom entities, list of lookup strategies (free-text, keywords). Both lookup strategies will be created if empty.",
optional: true,
options: [
"free-text",
"keywords",
],
},
},
methods: {
createEntity(args = {}) {
return this.app.post({
path: "/entities",
...args,
});
},
},
async run({ $ }) {
const {
createEntity,
name,
roles,
lookups,
} = this;

const response = await createEntity({
$,
data: {
name,
roles: utils.parseArray(roles),
lookups: utils.parseArray(lookups),
},
});

$.export("$summary", "Successfully created entity");

return response;
},
};
39 changes: 39 additions & 0 deletions components/wit_ai/actions/create-intent/create-intent.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import app from "../../wit_ai.app.mjs";

export default {
key: "wit_ai-create-intent",
name: "Create Intent",
description: "Creates a new intent. [See the documentation](https://wit.ai/docs/http/20240304/#post__intents_link)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
type: "string",
label: "Name",
description: "Name for the intent.",
},
},
methods: {
createIntent(args = {}) {
return this.app.post({
path: "/intents",
...args,
});
},
},
async run({ $ }) {
const {
createIntent,
name,
} = this;
const response = await createIntent({
$,
data: {
name,
},
});
$.export("$summary", "Successfully created intent");
return response;
},
};
Loading
Loading