Skip to content

Commit

Permalink
Merge pull request AlizerUncaged#69 from Alejandro-HUB/fix-hard-coded…
Browse files Browse the repository at this point in the history
…-paths

Fixed hard coded paths and made program more user-friendly
  • Loading branch information
AlizerUncaged authored Jun 12, 2023
2 parents d72d400 + 6c00cee commit 7b20faa
Show file tree
Hide file tree
Showing 28 changed files with 3,809 additions and 1,532 deletions.
2,276 changes: 2,276 additions & 0 deletions character_ai/package-lock.json

Large diffs are not rendered by default.

60 changes: 29 additions & 31 deletions character_ai/runner.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
let yandereGf = ""
let yandereGf = "";

let port = 40102
let port = 40102;

// the first argument is the port to run on
// the first argument is on index 2 for some reason
if (process.argv.length > 3) {
port = process.argv[3]
yandereGf = process.argv[2]
port = process.argv[3];
yandereGf = process.argv[2];
console.log(`Running on port ${port} with character ${yandereGf}`);
}

const readlineSync = require('readline-sync')
const WebSocket = require('ws')
var CharacterAI = require('./client')
global.client = new CharacterAI()
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});

const WebSocket = require('ws');
const CharacterAI = require('./client');

const client = new CharacterAI();
global.client = client;

const wss = new WebSocket.Server({ port: port });

Expand All @@ -24,48 +30,40 @@ wss.on('connection', (ws) => {
console.log('A client connected');

ws.on('message', async (message) => {

if (!global.yandereRoom)
{
console.log(`Unable to send message.`)
if (!global.yandereRoom) {
console.log(`Unable to send message.`);
console.log(`CharacterAI is still fetching character data!`);
console.log(`If it's taking far too long please submit an issue.`);
return
return;
}

let chatMessage = message.toString('utf8');

console.log(`Received message: ${chatMessage}`);

const response = await global.yandereRoom.sendAndAwaitResponse(chatMessage, true)

const response = await global.yandereRoom.sendAndAwaitResponse(chatMessage, true);
console.log(`Character: ${response.text}`);

ws.send(`${response.text}`);
});

});

async function main() {
console.log(`Authenticating....`);
await global.client.authenticateAsGuest();
await client.authenticateAsGuest();

console.log(`Authenticated, fetching character AI info....`);

var characterInfo = await global.client.fetchCharacterInfo(yandereGf);

global.yandereRoom = await global.client.createOrContinueChat(yandereGf);
const characterInfo = await client.fetchCharacterInfo(yandereGf);
global.yandereRoom = await client.createOrContinueChat(yandereGf);

console.log(`Character Name: ${characterInfo.name ?? "<Unkown>"}`);
console.log(`Greeting: ${characterInfo.greeting ?? "<Unkown>"}`);
console.log(`Character Id: ${global.yandereRoom.characterId ?? "<Unkown>"}`);
console.log(`Character Name: ${characterInfo.name ?? "<Unknown>"}`);
console.log(`Greeting: ${characterInfo.greeting ?? "<Unknown>"}`);
console.log(`Character Id: ${global.yandereRoom.characterId ?? "<Unknown>"}`);

/* while(true)
{
const message = readlineSync.question('You > ');
const response = await global.yandereRoom.sendAndAwaitResponse(message, true)
console.log('');
} */
readline.on('line', async (message) => {
const response = await global.yandereRoom.sendAndAwaitResponse(message, true);
console.log(`Character: ${response.text}`);
});
}

main();
main();
Loading

0 comments on commit 7b20faa

Please sign in to comment.