mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-13 12:06:06 -05:00
Chat Queue Persistence (#33)
* fix: workflow env * update: center title on readme * update: readme goals and format * add: icons in readme * fix: plus margin * update: environment variables in contr. * add: queue for chat history * add: set -e for workflow failure * update: version increment * fix: client null info * fix: shutoff issues
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ClientEvents, Awaitable, Client } from 'discord.js'
|
||||
import type { ClientEvents, Awaitable, Client, User } from 'discord.js'
|
||||
import { Ollama } from 'ollama'
|
||||
import { Queue } from '../queues/queue.js'
|
||||
|
||||
// Export events through here to reduce amount of imports
|
||||
export { Events } from 'discord.js'
|
||||
@@ -33,7 +34,7 @@ export type UserMessage = {
|
||||
export interface EventProps {
|
||||
client: Client
|
||||
log: LogMethod
|
||||
msgHist: { role: string, content: string }[]
|
||||
msgHist: Queue<UserMessage>
|
||||
tokens: Tokens,
|
||||
ollama: Ollama
|
||||
}
|
||||
@@ -63,7 +64,7 @@ export function event<T extends EventKeys>(key: T, callback: EventCallback<T>):
|
||||
export function registerEvents(
|
||||
client: Client,
|
||||
events: Event[],
|
||||
msgHist: UserMessage[],
|
||||
msgHist: Queue<UserMessage>,
|
||||
tokens: Tokens,
|
||||
ollama: Ollama
|
||||
): void {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { EmbedBuilder, Message } from 'discord.js'
|
||||
import { ChatResponse, Ollama } from 'ollama'
|
||||
import { UserMessage } from './events.js'
|
||||
import { Queue } from '../queues/queue.js'
|
||||
|
||||
/**
|
||||
* Method to send replies as normal text on discord like any other user
|
||||
@@ -15,7 +16,7 @@ export async function embedMessage(
|
||||
channel: string,
|
||||
model: string
|
||||
},
|
||||
msgHist: UserMessage[]
|
||||
msgHist: Queue<UserMessage>
|
||||
) {
|
||||
// bot response
|
||||
let response: ChatResponse
|
||||
@@ -33,7 +34,7 @@ export async function embedMessage(
|
||||
// Attempt to query model for message
|
||||
response = await ollama.chat({
|
||||
model: tokens.model,
|
||||
messages: msgHist,
|
||||
messages: msgHist.getItems(),
|
||||
options: {
|
||||
num_thread: 8, // remove if optimization needed further
|
||||
mirostat: 1,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Message } from 'discord.js'
|
||||
import { ChatResponse, Ollama } from 'ollama'
|
||||
import { UserMessage } from './events.js'
|
||||
import { Queue } from '../queues/queue.js'
|
||||
|
||||
/**
|
||||
* Method to send replies as normal text on discord like any other user
|
||||
@@ -15,7 +16,7 @@ export async function normalMessage(
|
||||
channel: string,
|
||||
model: string
|
||||
},
|
||||
msgHist: UserMessage[]
|
||||
msgHist: Queue<UserMessage>
|
||||
) {
|
||||
// bot's respnse
|
||||
let response: ChatResponse
|
||||
@@ -25,7 +26,7 @@ export async function normalMessage(
|
||||
// Attempt to query model for message
|
||||
response = await ollama.chat({
|
||||
model: tokens.model,
|
||||
messages: msgHist,
|
||||
messages: msgHist.getItems(),
|
||||
options: {
|
||||
num_thread: 8, // remove if optimization needed further
|
||||
mirostat: 1,
|
||||
|
||||
Reference in New Issue
Block a user