Skip to content

Commit

Permalink
fix(tetsing-deployment)
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-Knight committed Jul 23, 2024
1 parent 4cefa3a commit 51cc9b0
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions src/train.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@

import fs from 'fs'

import fs from 'fs';
import { NlpManager } from 'node-nlp';
import path from 'path';
import dotenv from 'dotenv';

export const manager = new NlpManager({ languages: ["en"] });
dotenv.config();

async function trainManager() {
const intentFiles = fs.readdirSync('./intents');
const intentsPath = process.env.INTENTS_PATH || path.resolve(__dirname, '../Intents');

for (const file of intentFiles) {
try {
const filePath = `./intents/${file}`;
const data = await fs.promises.readFile(filePath, 'utf8');
const jsonData = JSON.parse(data);
export const manager = new NlpManager({ languages: ['en'] });

const intent = file.replace('.json', '');

for (const utterances of jsonData.utterances) {
manager.addDocument('en', utterances, intent);
}

for (const responses of jsonData.responses) {
manager.addAnswer('en', intent, responses);
async function trainManager() {
try {
const intentFiles = await fs.promises.readdir(intentsPath);

for (const file of intentFiles) {
try {
const filePath = path.join(intentsPath, file);
const data = await fs.promises.readFile(filePath, 'utf8');
const jsonData = JSON.parse(data);

const intent = file.replace('.json', '');

for (const utterance of jsonData.utterances) {
manager.addDocument('en', utterance, intent);
}

for (const response of jsonData.responses) {
manager.addAnswer('en', intent, response);
}
} catch (error) {
console.error(`Error processing intent file ${file}:`, error);
}
} catch (error) {
console.error(`Error processing intent file ${file}:`, error);
}
}

await manager.train();
await manager.train();
} catch (error) {
console.error('Error reading intent files:', error);
}
}

trainManager()
.then(async () => {
manager.save();
await manager.save();
})
.catch((error) => console.error('Error training NLP manager:', error));
.catch(error => console.error('Error training NLP manager:', error));

module.exports = {
manager,
trainManager
};
module.exports = {
manager,
trainManager,
};

0 comments on commit 51cc9b0

Please sign in to comment.