Add Server

This commit is contained in:
reis
2022-11-10 13:55:33 +00:00
parent c196886d06
commit 9962e4fe68
9 changed files with 336 additions and 0 deletions

31
server/index.js Normal file
View File

@@ -0,0 +1,31 @@
import { createServer } from 'node:net';
import { deserialize } from 'bson';
import FastText from 'fasttext.js';
import { runAI, trainAI } from './events/index.js';
const ft = new FastText({
loadModel: './model/model.bin'
});
ft.load();
const server = createServer(async (client) => {
client.on('data', async (data) => {
const eventData = deserialize(data);
switch(eventData.event) {
case 'ai': {
runAI(client, eventData, ft.predict);
break;
}
case 'train_ai': {
trainAI(ft.unload, ft.load);
break;
}
}
});
});
server.listen(process.env.PORT || 3000);