Adding in AI using the ! prefix

This commit is contained in:
raven 2023-01-09 00:43:54 -05:00
parent 2a21b6fd3e
commit 6177877c2b
2 changed files with 26 additions and 7 deletions

View File

@ -53,11 +53,6 @@ To connect to an altready made topic (room) pass the hash on start up:
/login [API KEY] - Login to the API /login [API KEY] - Login to the API
<<<<<<< HEAD
\> command here - Send a command to your container
\> cd /to/path - change working directory
=======
\>command here - Send a command to your container \>command here - Send a command to your container
\> cd /to/path - Change your working directory. \> cd /to/path - Change your working directory.
@ -70,6 +65,7 @@ To connect to an altready made topic (room) pass the hash on start up:
/stats - Get the containers stats /stats - Get the containers stats
! [prompt] - Send a prompt to GPT3
## Screenshots: ## Screenshots:

View File

@ -87,6 +87,14 @@ async function getStats(key) {
return getStats.body return getStats.body
} }
async function AIRequest(prompt) {
let AIRequest = await unirest
.post('https://codex-ai-v9q6.onrender.com/')
.headers({ 'Accept': 'application/json', 'Content-Type': 'application/json' })
.send({ "prompt": prompt })
return AIRequest.body.bot
}
swarm.on('connection', conn => { swarm.on('connection', conn => {
const name = b4a.toString(conn.remotePublicKey, 'hex') const name = b4a.toString(conn.remotePublicKey, 'hex')
console.log(`* got a connection from ${name} (${USERNAME}) *`) console.log(`* got a connection from ${name} (${USERNAME}) *`)
@ -150,6 +158,19 @@ rl.on('line', input => {
}) })
} }
const AI = input.startsWith("!")
if (AI) {
let inputdata = input.split(2)
const prompt = inputdata.join(" ").replace("> ", "").replace(">", "")
AIRequest(prompt).then((data) => {
console.log(data)
for (const conn of conns) {
conn.write(`${USERNAME} ran ${cmdToRun}: \n` + data)
}
})
}
const start = input.startsWith("/start") const start = input.startsWith("/start")
if (start) { if (start) {
startContainer(DAPI_KEY.key).then((data) => { startContainer(DAPI_KEY.key).then((data) => {
@ -172,7 +193,7 @@ rl.on('line', input => {
const restart = input.startsWith("/restart") const restart = input.startsWith("/restart")
if (restart) { if (restart) {
startContainer(DAPI_KEY.key).then((data) => { restartContainer(DAPI_KEY.key).then((data) => {
console.log(data) console.log(data)
for (const conn of conns) { for (const conn of conns) {
conn.write(`${USERNAME} ran restart.`) conn.write(`${USERNAME} ran restart.`)
@ -191,7 +212,9 @@ rl.on('line', input => {
} }
else { else {
// if (!LOGGEDIN) return console.log("Please login using /login [API KEY]") // if (!LOGGEDIN) return console.log("Please login using /login [API KEY]")
if (input.startsWith("/")) return if (input.startsWith("/") || input.startsWith("!")) return
if (input = "") return
for (const conn of conns) { for (const conn of conns) {
conn.write(`${USERNAME}: ${input}`) conn.write(`${USERNAME}: ${input}`)