Skip to content

Commit

Permalink
Merge pull request #42 from sirkitree/main
Browse files Browse the repository at this point in the history
provide a way to chat directly with the agent via the command line
  • Loading branch information
lalalune authored Oct 27, 2024
2 parents 0ecc1b7 + eeeed7d commit 901b092
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,38 @@ const startAgents = async () => {

startAgents();

// way for user input to quit
const stdin = process.stdin;
import readline from 'readline';

stdin.resume();
stdin.setEncoding("utf8");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

console.log("Press Ctrl+C to quit");
function chat() {
rl.question('You: ', async (input) => {
if (input.toLowerCase() === 'exit') {
rl.close();
return;
}

const agentId = characters[0].name.toLowerCase(); // Assuming we're using the first character
const response = await fetch(`http://localhost:3000/${agentId}/message`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: input,
userId: 'user',
userName: 'User',
}),
});

const data = await response.json();
console.log(`${characters[0].name}: ${data.text}`);
chat();
});
}

console.log("Chat started. Type 'exit' to quit.");
chat();

0 comments on commit 901b092

Please sign in to comment.