feat: training and replies changed

This commit is contained in:
GramingFoxTeam
2023-03-20 21:28:52 +03:00
parent 1909e2c421
commit 715aa918cf
16 changed files with 187 additions and 106 deletions

View File

@@ -2,7 +2,7 @@
The server uses TCP for connection and BSON for messages, so you need to serialize and deserialize the messages.
# AI
## AI
Sending the server this JSON (BSON) will send you back the AI predictions.
@@ -20,11 +20,28 @@ And the server would return something like this:
{
"op": 2,
"id": "String",
"response": "I think the term afn is just a generic slang term for the app that allows you to modify the behavior of Dalvik based android application..."
"response": [
{
"confidence": 0.99,
"id": "String",
"name": "revanced_download"
}
]
```
### Training the AI
To train the AI, send the server a JSON (BSON) like this:
```json
{
"op": 3,
"label": "revanced_download",
"text": "how to download revanced"
}
```
# OCR
## OCR
Sending the server this JSON (BSON) will send you back the read text.

View File

@@ -1,11 +1,14 @@
import { serialize } from 'bson';
export default async function runAI(client, data, config) {
const witAIReq = await fetch(`https://api.wit.ai/message?v20230319&q=${encodeURI(data.text)}`, {
headers: {
authorization: `Bearer ${config.authToken}`
const witAIReq = await fetch(
`https://api.wit.ai/message?v20230319&q=${encodeURI(data.text)}`,
{
headers: {
authorization: `Bearer ${config.authToken}`
}
}
});
);
const response = await witAIReq.json();

View File

@@ -1,4 +1,5 @@
import runAI from './ai.js';
import runOCR from './ocr.js';
import trainAI from './train.js';
export { runAI, runOCR };
export { runAI, runOCR, trainAI };

18
server/events/train.js Normal file
View File

@@ -0,0 +1,18 @@
export default async function runAI(data, config) {
fetch('https://api.wit.ai/utterances', {
headers: {
authorization: `Bearer ${config.authToken}`
},
body: JSON.stringify([
{
text: data.text,
intent: data.label,
entities: [],
traits: []
}
]),
method: 'POST'
});
return;
}

View File

@@ -3,7 +3,7 @@ const config = JSON.parse(readFileSync('./config.json', 'utf-8'));
import { createServer } from 'node:net';
import { deserialize } from 'bson';
import { runAI, runOCR } from './events/index.js';
import { runAI, runOCR, trainAI } from './events/index.js';
const server = createServer(async (client) => {
client.on('data', async (data) => {
@@ -17,6 +17,11 @@ const server = createServer(async (client) => {
break;
}
case 3: {
trainAI(eventData, config.witAI);
break;
}
case 5: {
runOCR(client, eventData);
break;