Skip to content

Commit

Permalink
add username to metadata openai
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Nov 14, 2024
1 parent b11743e commit 9f8dc70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion handlers/openAI.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const moment = require("moment/moment");

class OpenAI {
async askOpenAI (target, text, username, bot) {
const response = await OpenAIService.askAssistant(text)
const response = await OpenAIService.askAssistant(text, username)
if (response) {
bot.say(target, `@${username} ${response}`)
}
Expand Down
8 changes: 5 additions & 3 deletions lib/messenger.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class Messenger {
async handleText (target, context, msg, self) {
if (self) { return; } // Ignore messages from the bot

await Logger.logChatMessage(context['room-id'], context['username'], msg)
if (context['username'].toLowerCase() !== config.twitch.username.toLowerCase())
await Logger.logChatMessage(context['room-id'], context['username'], msg)


const text = msg.trim();
const textSplit = text.split(' ')
Expand Down Expand Up @@ -182,11 +184,11 @@ class Messenger {
return handlers.events.sendTarracoMangaEvent()

// OPEN AI
if (textSplit.length > 1 && inputParser.isAskingOpenAI(textSplit[0]) && this._isNotCooldown('openai',10)) {
if (textSplit.length > 1 && inputParser.isAskingOpenAI(textSplit[0]) && this._isNotCooldown('openai',15)) {
return handlers.openAI.askOpenAI(target, textSplit.slice(1).join(' '), context['display-name'], this.bot)
}

if (textSplit.length > 1 && inputParser.isAskingBotOpenAI(text) && this._isNotCooldown('openai',10)) {
if (textSplit.length > 1 && inputParser.isAskingBotOpenAI(text) && this._isNotCooldown('openai',15)) {
const regex = new RegExp(`@?${config.twitch.username}`, 'gi')
const textWithoutMention = text.replace(regex, '').trim()
return handlers.openAI.askOpenAI(target, textWithoutMention, context['display-name'], this.bot)
Expand Down
5 changes: 4 additions & 1 deletion services/openAI.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async function uploadFileToVectorStore(json, formattedDate, origin) {



async function askAssistant(message) {
async function askAssistant(message, username) {
let result
try {
// Create a thread
Expand All @@ -93,6 +93,9 @@ async function askAssistant(message) {
{
role: "user",
content: "dime en 200 caracteres " + message,
metadata: {
nick: username,
}
}
);

Expand Down

0 comments on commit 9f8dc70

Please sign in to comment.