snips-sam
Version:
The Snips Assistant Manager
28 lines (22 loc) • 979 B
text/typescript
import { SkillLang } from '../models/language';
const shell = require('shelljs');
export class Exec {
static exec(language: SkillLang | undefined, actionBlock: string, slots: {[name: string]: string}): any | undefined {
switch (language) {
case SkillLang.PYTHON:
return Exec.pythonExec(actionBlock, slots);
default:
break;
}
}
static pythonExec(actionBlock: string, slots: {[name: string]: string}): any {
let actionBlockReplaced = actionBlock.replace(/tts_service.speak\(/g, `print('TTS says: ' + `);
for (const slotName in slots) {
const slotValue = slots[slotName];
const regex = new RegExp(`intent.${slotName}`, 'g');
actionBlockReplaced = actionBlockReplaced.replace(regex, slotValue);
}
const code = `<<EOF\n${actionBlock}\nEOF`;
return shell.exec(`python - ${code}`, { async: true, silent: true });
}
}