User Preferences and Setup Docs (#20)

* added message style command

* docker setup scripts

* reformat messageStyle.ts

* fix: register unregister on deploy

* add: messageStream preference

* add: json config handler

* update: messageCreate gets config

* update: shifted chat to config callback

* fix: naming conventions based on discord

* update: setup in docs now

* add: static docker ips

* version increment

* add: bot message for no config

* fix: no config case

* add: clarification for subnetting

* update: version increment in lock file

---------

Co-authored-by: JT2M0L3Y <jtsmoley@icloud.com>
This commit is contained in:
Kevin Dang
2024-03-22 10:37:06 -07:00
committed by GitHub
parent 5e74736c57
commit 43fb2ea94e
20 changed files with 377 additions and 146 deletions

View File

@@ -8,7 +8,7 @@ import commands from '../commands/index.js'
export default event(Events.InteractionCreate, async ({ log, client }, interaction) => {
if (!interaction.isCommand() || !interaction.isChatInputCommand()) return
log(`Interaction called \'${interaction.commandName}\' from ${interaction.client.user.tag}.`)
log(`Interaction called \'${interaction.commandName}\' from ${interaction.user.tag}.`)
// ensure command exists, otherwise kill event
const command = commands.find(command => command.name === interaction.commandName)

View File

@@ -1,11 +1,13 @@
import { embedMessage, event, Events } from '../utils/index.js'
import { ChatResponse } from 'ollama'
import { embedMessage, event, Events, normalMessage } from '../utils/index.js'
import { Configuration, getConfig } from '../utils/jsonHandler.js'
/**
* Max Message length for free users is 2000 characters (bot or not).
* @param message the message received from the channel
*/
export default event(Events.MessageCreate, async ({ log, msgHist, tokens, ollama }, message) => {
log(`Message created \"${message.content}\" from ${message.author.tag}.`)
log(`Message \"${message.content}\" from ${message.author.tag} in channel/thread ${message.channelId}.`)
// Hard-coded channel to test output there only, in our case "ollama-endpoint"
if (message.channelId != tokens.channel) return
@@ -22,18 +24,36 @@ export default event(Events.MessageCreate, async ({ log, msgHist, tokens, ollama
content: message.content
})
// Try to query and send embed
const response = await embedMessage(message, ollama, tokens, msgHist)
// Try to query and send embed
try {
const config: Configuration = await new Promise((resolve, reject) => {
getConfig('config.json', (config) => {
if (config === undefined) {
reject(new Error('No Configuration is set up.'))
return
}
resolve(config)
})
})
// Try to query and send message
// log(normalMessage(message, tokens, msgHist))
let response: ChatResponse
// If something bad happened, remove user query and stop
if (response == undefined) { msgHist.pop(); return }
// undefined or false, use normal, otherwise use embed
if (config.options['message-style'])
response = await embedMessage(message, ollama, tokens, msgHist)
else
response = await normalMessage(message, ollama, tokens, msgHist)
// successful query, save it as history
msgHist.push({
role: 'assistant',
content: response.message.content
})
// If something bad happened, remove user query and stop
if (response == undefined) { msgHist.pop(); return }
// successful query, save it as history
msgHist.push({
role: 'assistant',
content: response.message.content
})
} catch (error: any) {
msgHist.pop() // remove message because of failure
message.reply(`**Response generation failed.**\n\nReason: ${error.message}\n\nPlease use any config slash command.`)
}
})