Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

[Botskills] Implement refresh command #1480

Merged
merged 15 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
11 changes: 10 additions & 1 deletion docs/howto/skills/addingskills.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,13 @@ botskills disconnect --skillId SKILL_ID
> Note: The id of the Skill can also be aquired using the `botskills list` command. You can check the [Skill CLI documentation](/lib/typescript/botskills/docs/list.md) on this command.
## Updating an existing Skill to reflect changes to Actions or LUIS model

> A botskills refresh command will be added shortly. In the meantime, run the above disconnect command and then connect the skill again.
> A botskills refresh command will be added shortly. In the meantime, run the above disconnect command and then connect the skill again.

## Train Connected Skills
To train your connected skills use the following command, specifying the `--cs` (for C#) or `--ts` (for TypeScript) argument for determining the coding language of your assistant, since each language takes different folder structures that need to be taken into consideration.

botskills:

```bash
botskills train --cs
```
7 changes: 5 additions & 2 deletions lib/typescript/botskills/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ npm uninstall -g botskills
```

## Botskills functionality
- [Connect](./docs/connect-disconnect.md) a Skill to your assistant
- [Disconnect](./docs/connect-disconnect.md) a Skill from your assistant
- [Connect](./docs/connect-disconnect.md#connect-a-skill-to-your-assistant) a Skill to your assistant
- [Disconnect](./docs/connect-disconnect.md#disconnect-a-skill-to-your-assistant) a Skill from your assistant
- [Train](./docs/train.md) connected skills
- [List](./docs/list.md) all Skills connected to your assistant

## Daily builds
Expand All @@ -36,3 +37,5 @@ npm install -g botskills --registry https://botbuilder.myget.org/F/aitemplates/n
## Further Reading
- [Create and customize Skills for your assistant](../../../docs/tutorials/typescript/skill.md)
- [Connect a Skill to your Assistant](../../../docs/howto/skills/addingskills.md)
- [Disconnect a Skill to your Assistant](../../../docs/howto/skills/addingskills.md#remove-a-skill-from-your-virtual-assistant)
- [Train Connected Skills](../../../docs/howto/skills/addingskills.md#train-connected-skills)
8 changes: 4 additions & 4 deletions lib/typescript/botskills/docs/connect-disconnect.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ botskills connect [options]
| -l, --localManifest \<path> | Path to local Skill Manifest file |
| -r, --remoteManifest \<url> | URL to remote Skill Manifest |
| --cs | Determine your assistant project structure to be a csharp-like structure |
| --ts | Determine your assistant project structure to be a TypeScript-like structure
| --noTrain | (OPTIONAL) Determine whether the skills connected are not going to be trained (by default they are trained) |
| --ts | Determine your assistant project structure to be a TypeScript-like structure |
| --noTrain | (OPTIONAL) Determine whether the skills connected are not going to be trained (by default they are trained) |
| --dispatchName [name] | (OPTIONAL) Name of your assistant's '.dispatch' file (defaults to the name displayed in your Cognitive Models file) |
| --language [language] | (OPTIONAL) Locale used for LUIS culture (defaults to 'en-us') |
| --luisFolder [path] | (OPTIONAL) Path to the folder containing your Skills' '.lu' files (defaults to './deployment/resources/skills/en' inside your assistant folder) |
Expand Down Expand Up @@ -65,8 +65,8 @@ botskills disconnect [option]
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -i, --skillId \<id> | Id of the skill to remove from your assistant (case sensitive) |
| --cs | Determine your assistant project structure to be a csharp-like structure |
| --ts | Determine your assistant project structure to be a TypeScript-like structure
| --noTrain | (OPTIONAL) Determine whether the skills connected are not going to be trained (by default they are trained) |
| --ts | Determine your assistant project structure to be a TypeScript-like structure |
| --noTrain | (OPTIONAL) Determine whether the skills connected are not going to be trained (by default they are trained) |
| --dispatchName [name] | (OPTIONAL) Name of your assistant's '.dispatch' file (defaults to the name displayed in your Cognitive Models file) |
| --dispatchFolder [path] | (OPTIONAL) Path to the folder containing your assistant's '.dispatch' file (defaults to './deployment/resources/dispatch/en' inside your assistant folder) |
| --outFolder [path] | (OPTIONAL) Path for any output file that may be generated (defaults to your assistant's root folder) |
Expand Down
33 changes: 33 additions & 0 deletions lib/typescript/botskills/docs/train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Train Connected Skills

The `train` command allows you to train your connected skills specifying the assistant's coding language using `--cs` or `--ts`.

> **Tip:** It's highly advisable to execute this command from the root folder of your assistant bot, so if you are using the suggested folder structure from the Templates, you may ommit most of the optional arguments, as they default to the expected values from the Templates' folder structure.

The basic command to train your connected skills:

```bash
botskills train [options]
```

### Options

| Option | Description |
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| --cs | Determine your assistant project structure to be a csharp-like structure |
| --ts | Determine your assistant project structure to be a TypeScript-like structure |
| --dispatchName [name] | (OPTIONAL) Name of your assistant's '.dispatch' file (defaults to the name displayed in your Cognitive Models file) |
| --language [language] | (OPTIONAL) Locale used for LUIS culture (defaults to 'en-us') |
| --luisFolder [path] | (OPTIONAL) Path to the folder containing your Skills' '.lu' files (defaults to './deployment/resources/skills/en' inside your assistant folder) |
| --dispatchFolder [path] | (OPTIONAL) Path to the folder containing your assistant's '.dispatch' file (defaults to './deployment/resources/dispatch/en' inside your assistant folder) |
| --outFolder [path] | (OPTIONAL) Path for any output file that may be generated (defaults to your assistant's root folder) |
| --lgOutFolder [path] | (OPTIONAL) Path for the LuisGen output (defaults to a 'service' folder inside your assistant's folder) |
| --cognitiveModelsFile [path] | (OPTIONAL) Path to your Cognitive Models file (defaults to 'cognitivemodels.json' inside your assistant's folder) |
| --verbose | (OPTIONAL) Output detailed information about the processing of the tool |
| -h, --help | Output usage information |

An example on how to use:

```bash
botskills train --cs --verbose
```
4 changes: 2 additions & 2 deletions lib/typescript/botskills/src/botskills-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as program from 'commander';
import { existsSync } from 'fs';
import { extname, isAbsolute, join, resolve } from 'path';
import { connectSkill } from './functionality';
import { ConnectSkill } from './functionality';
import { ConsoleLogger, ILogger } from './logger';
import { ICognitiveModelFile, IConnectConfiguration } from './models';
import { validatePairOfArgs } from './utils';
Expand Down Expand Up @@ -163,4 +163,4 @@ configuration.logger = logger;

// End of arguments validation

connectSkill(<IConnectConfiguration> configuration);
new ConnectSkill(logger).connectSkill(<IConnectConfiguration> configuration);
102 changes: 102 additions & 0 deletions lib/typescript/botskills/src/botskills-train.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* Copyright(c) Microsoft Corporation.All rights reserved.
* Licensed under the MIT License.
*/

import * as program from 'commander';
import { join, resolve } from 'path';
import { TrainSkill } from './functionality';
import { ConsoleLogger, ILogger} from './logger';
import { ICognitiveModelFile, ITrainConfiguration } from './models';
import { validatePairOfArgs } from './utils';

function showErrorHelp(): void {
program.outputHelp((str: string) => {
logger.error(str);

return '';
});
process.exit(1);
}

const logger: ILogger = new ConsoleLogger();

program.Command.prototype.unknownOption = (flag: string): void => {
logger.error(`Unknown arguments: ${flag}`);
showErrorHelp();
};

// tslint:disable: max-line-length
program
.name('botskills train')
.description('Train the connected skills.')
.option('--cs', 'Determine your assistant project structure to be a CSharp-like structure')
.option('--ts', 'Determine your assistant project structure to be a TypeScript-like structure')
.option('--dispatchName [name]', '[OPTIONAL] Name of your assistant\'s \'.dispatch\' file (defaults to the name displayed in your Cognitive Models file)')
.option('--language [language]', '[OPTIONAL] Locale used for LUIS culture (defaults to \'en-us\')')
.option('--luisFolder [path]', '[OPTIONAL] Path to the folder containing your Skills\' .lu files (defaults to \'./deployment/resources/skills/en\' inside your assistant folder)')
.option('--dispatchFolder [path]', '[OPTIONAL] Path to the folder containing your assistant\'s \'.dispatch\' file (defaults to \'./deployment/resources/dispatch/en\' inside your assistant folder)')
.option('--outFolder [path]', '[OPTIONAL] Path for any output file that may be generated (defaults to your assistant\'s root folder)')
.option('--lgOutFolder [path]', '[OPTIONAL] Path for the LuisGen output (defaults to a \'service\' folder inside your assistant\'s folder)')
.option('--cognitiveModelsFile [path]', '[OPTIONAL] Path to your Cognitive Models file (defaults to \'cognitivemodels.json\' inside your assistant\'s folder)')
.option('--verbose', '[OPTIONAL] Output detailed information about the processing of the tool')
.action((cmd: program.Command, actions: program.Command) => undefined);

const args: program.Command = program.parse(process.argv);

if (process.argv.length < 3) {
program.help();
}

logger.isVerbose = args.verbose;

// Validation of arguments
// cs and ts validation
const csAndTsValidationResult: string = validatePairOfArgs(args.cs, args.ts);
if (csAndTsValidationResult) {
logger.error(
csAndTsValidationResult.replace('{0}', 'cs')
.replace('{1}', 'ts')
);
process.exit(1);
}

const projectLanguage: string = args.cs ? 'cs' : 'ts';
// Initialize an instance of IConnectConfiguration to send the needed arguments to the connectSkill function
const configuration: Partial<ITrainConfiguration> = {
lgLanguage: projectLanguage
};

// language validation
const language: string = args.language || 'en-us';
configuration.language = language;
const languageCode: string = (language.split('-'))[0];

// outFolder validation -- the const is needed for reassuring 'configuration.outFolder' is not undefined
const outFolder: string = args.outFolder || resolve('./');
configuration.outFolder = outFolder;

// cognitiveModelsFile validation
const cognitiveModelsFilePath: string = args.cognitiveModelsFile || join(configuration.outFolder, (args.ts ? join('src', 'cognitivemodels.json') : 'cognitivemodels.json'));
configuration.cognitiveModelsFile = cognitiveModelsFilePath;
// luisFolder validation
configuration.luisFolder = args.luisFolder || join(configuration.outFolder, 'Deployment', 'Resources', 'Skills', languageCode);

// dispatchFolder validation
configuration.dispatchFolder = args.dispatchFolder || join(configuration.outFolder, 'Deployment', 'Resources', 'Dispatch', languageCode);

// lgOutFolder validation
configuration.lgOutFolder = args.lgOutFolder || join(configuration.outFolder, (args.ts ? join('src', 'Services') : 'Services'));

// dispatchName validation
if (!args.dispatchName) {
// try get the dispatch name from the cognitiveModels file
// tslint:disable-next-line
const cognitiveModelsFile: ICognitiveModelFile = require(cognitiveModelsFilePath);
configuration.dispatchName = cognitiveModelsFile.cognitiveModels[languageCode].dispatchModel.name;
}

configuration.logger = logger;
// End of arguments validation

new TrainSkill(logger).trainSkill(<ITrainConfiguration> configuration);
1 change: 1 addition & 0 deletions lib/typescript/botskills/src/botskills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ program
program
.command('connect', 'connect any skill to your assistant bot')
.command('disconnect', 'disconnect a specific skill from your assitant bot')
.command('train', 'train the connected skills')
.command('list', 'list the connected skills in the assistant');

const args: program.Command = program.parse(process.argv);
Expand Down
Loading