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