bot can edit message response

This commit is contained in:
Kevin Dang
2024-01-23 14:44:30 -08:00
committed by Kevin Dang
parent 70103c1f5a
commit f8956b0b50

View File

@@ -8,30 +8,25 @@ export default event(Events.MessageCreate, ({ log }, message) => {
log(`Message created \"${message.content}\" from ${message.author.tag}.`) log(`Message created \"${message.content}\" from ${message.author.tag}.`)
// Hard-coded channel to test output there only, in our case "ollama-endpoint" // Hard-coded channel to test output there only, in our case "ollama-endpoint"
if (message.channelId != '1188262786497785896') { if (message.channelId != '1188262786497785896') return
log(`Unauthorized Channel input, Aborting...`)
return
}
log(`Channel id OK!`)
// Do not respond if bot talks in the chat // Do not respond if bot talks in the chat
if (message.author.tag === message.client.user.tag) { if (message.author.tag === message.client.user.tag) return
log(`Found Bot message reply, Aborting...`)
return
}
log(`Sender Checked!`)
// Reply with something to prompt that ollama is working
message.reply("Generating Response...").then(sentMessage => {
// Request made to API // Request made to API
const request = async () => { const request = async () => {
try { try {
// change this when using an actual hosted server or use ollama.js
const response = await Axios.post('http://127.0.0.1:11434/api/generate', { const response = await Axios.post('http://127.0.0.1:11434/api/generate', {
model: 'llama2', model: 'llama2',
prompt: message.content, prompt: message.content,
stream: false stream: false
}) })
log(response.data) log(response.data)
//
message.reply(response.data['response']) sentMessage.edit(response.data.response)
} catch (error) { } catch (error) {
log(error) log(error)
} }
@@ -39,4 +34,5 @@ export default event(Events.MessageCreate, ({ log }, message) => {
// Attempt to call ollama's endpoint // Attempt to call ollama's endpoint
request() request()
})
}) })