mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 19:56:06 -05:00
hardcoded and mentions
* added options to queries * removed hard coded vals, added message options * updated importing * added check for message mentions * fix missing botID * updated token to uid * added contributer --------- Co-authored-by: JT2M0L3Y <jtsmoley@icloud.com>
This commit is contained in:
48
src/utils/messageNormal.ts
Normal file
48
src/utils/messageNormal.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Message } from "discord.js";
|
||||
import ollama, { ChatResponse } from "ollama";
|
||||
|
||||
/**
|
||||
* Method to send replies as normal text on discord like any other user
|
||||
* @param message message sent by the user
|
||||
* @param tokens tokens to run query
|
||||
* @param msgHist message history between user and model
|
||||
*/
|
||||
export function normalMessage(
|
||||
message: Message,
|
||||
tokens: {
|
||||
channel: string,
|
||||
model: string
|
||||
},
|
||||
msgHist: {
|
||||
role: string,
|
||||
content: string
|
||||
}[]
|
||||
) {
|
||||
// bot's respnse
|
||||
let response: ChatResponse
|
||||
|
||||
message.reply('Generating Response . . .').then(async sentMessage => {
|
||||
try {
|
||||
// Attempt to query model for message
|
||||
response = await ollama.chat({
|
||||
model: tokens.model,
|
||||
messages: msgHist,
|
||||
options: {
|
||||
num_thread: 8, // remove if optimization needed further
|
||||
mirostat: 1,
|
||||
mirostat_tau: 2.0,
|
||||
top_k: 70
|
||||
},
|
||||
stream: false
|
||||
})
|
||||
|
||||
// edit the 'generic' response to new message
|
||||
sentMessage.edit(response.message.content)
|
||||
} catch(error: any) {
|
||||
sentMessage.edit(error.error)
|
||||
}
|
||||
})
|
||||
|
||||
// Hope there is a response, force client to believe
|
||||
return response!!
|
||||
}
|
||||
Reference in New Issue
Block a user