feat: zeon ai

This commit is contained in:
Saahil 2024-11-19 11:17:25 -05:00 committed by GitHub
parent 5bfb6b1eba
commit 5e5c8be465
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 106 additions and 12 deletions

View file

@ -18,11 +18,12 @@
"simple-json-db": "^2.0.0",
"smee-client": "^2.0.3",
"stegcloak": "^1.1.1",
"ws": "^8.18.0"
"ws": "^8.18.0",
"openai": "latest"
},
"devDependencies": {
"@types/node": "^22.7.4",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
}
}
}

View file

@ -27,17 +27,7 @@ const clean = async (text) => {
// Send off the cleaned up result
return text;
};
//eg: zeon can you set a timer for 10 minutes
// plan: use ai to parse it for ME ONLY
// everyone else act like a nice soul and use if statements
/**
* Only respond in JSON, no codeblock. Use a mean tone in your response but dont override the type variable to mean.in your json please give a property of type based on what the user is asking. All timestamps must be in unix. All durations must be in miliseconds.
The users'sprompt is: zeon can you tell me what 1+1 is <ac prompt>
*/
function zeonMessageCommands(d, r) {
// TODO: im eepy buddy
}
export default class Message implements Command {
name: string;
description: string;

View file

@ -0,0 +1,99 @@
// @ts-nocheck
import { App } from "@slack/bolt";
import util from "util";
import { Command, onlyForMe } from "../modules/BaseCommand";
import OpenAI from 'openai';
const ai = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
//eg: zeon can you set a timer for 10 minutes
// plan: use ai to parse it for ME ONLY
// everyone else act like a nice soul and use if statements
/**
* Only respond in JSON, no codeblock. Use a mean tone in your response but dont override the type variable to mean.in your json please give a property of type based on what the user is asking. All timestamps must be in unix. All durations must be in miliseconds.
The users'sprompt is: zeon can you tell me what 1+1 is <ac prompt>
*/
function zeonMessageCommands(d, r) {
// TODO: im eepy buddy
}
export default class Message implements Command {
name: string;
description: string;
is_event?: boolean;
constructor() {
this.name = `message`;
this.description = `Handles zeon.`;
this.is_event = true;
}
run(app: App) {
// app.command()
app.event(this.name, async (par) => {
// console.debug(par);
// if (!par.ack) return;
// console.debug(0);
if (!par.say) return;
// console.log(
// `uh one of them are here`,
// par.event.text,
// par.event.channel_type,
// );
//@ts-ignore
// await par.ack();
if (!par.event.text.startsWith("zeon")) return;
console.debug(`cmd`);
const { event, say } = par;
const args = event.text.slice("zeon ".length).trim().split(/ +/);
const cmd = args.shift().toLowerCase();
if (onlyForMe(command.user_id)) {
let prompt = `Only respond in JSON, no codeblock. Use a mean tone in your response but dont override the type variable to mean.in your json please give a property of type based on what the user is asking. All timestamps must be in unix. All durations must be in miliseconds. `
const aiReq = await ai.chat.completions.create({
messages: [{role: 'system', content: prompt },{ role: 'user', content: event.text }],
model: 'gpt-3.5-turbo',
});
const m = await app.client.postMessage({
channel: event.channel,
text: aiReq.message || ":notcool: i didnt get a message im very scared... >> " + JSON.stringify(aiReq),
})
switch (aiReq.type) {
case "reminder":
case "timer":
// uhhh todo??
setTimeout(() => {
app.client.chat.postMessage({
channel: event.channel,
text: "reminder time",
thread_ts: m.ts
})
}, aiReq.duration)
break;
default:
console.log(aiReq, `unk`)
break;
}
} else {
// console.log(cmd, args);
const actionVerbs = ["can", "please", "plz"]
const uneededVerbsInSomeCases = ["you", "a"]
if (actionVerbs.includes(cmd)) {
// try to understand
if (uneededVerbsInSomeCases.includes(args[0].toLowerCase())) {
args.shift() // get rid of it
// timer func
}
}
}
console.debug(`#message3-`);
//@ts-ignore
// await say(`Hi there! im a WIP rn but my site is:\n> http://zeon.rocks/`);
});
}
}

View file

@ -0,0 +1,4 @@
export default function watchLocation() {
const location = null;
// todo
}