mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 11:56:06 -05:00
bot can edit message response
This commit is contained in:
@@ -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)
|
||||
|
||||
// Attempt to call ollama's endpoint
|
||||
request()
|
||||
sentMessage.edit(response.data.response)
|
||||
} catch (error) {
|
||||
log(error)
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt to call ollama's endpoint
|
||||
request()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user