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}.`)
|
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!`)
|
|
||||||
|
|
||||||
// Request made to API
|
// Reply with something to prompt that ollama is working
|
||||||
const request = async () => {
|
message.reply("Generating Response...").then(sentMessage => {
|
||||||
try {
|
// Request made to API
|
||||||
const response = await Axios.post('http://127.0.0.1:11434/api/generate', {
|
const request = async () => {
|
||||||
model: 'llama2',
|
try {
|
||||||
prompt: message.content,
|
// change this when using an actual hosted server or use ollama.js
|
||||||
stream: false
|
const response = await Axios.post('http://127.0.0.1:11434/api/generate', {
|
||||||
})
|
model: 'llama2',
|
||||||
log(response.data)
|
prompt: message.content,
|
||||||
//
|
stream: false
|
||||||
message.reply(response.data['response'])
|
})
|
||||||
} catch (error) {
|
log(response.data)
|
||||||
log(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to call ollama's endpoint
|
sentMessage.edit(response.data.response)
|
||||||
request()
|
} catch (error) {
|
||||||
|
log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to call ollama's endpoint
|
||||||
|
request()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user