Compare commits

...

1 Commits

Author SHA1 Message Date
Kevin Dang
2a39e20fee Text Files As Prompts (#156)
* Add: .txt file reading

* Update: version increment
2025-01-31 14:12:11 -08:00
6 changed files with 26 additions and 10 deletions

View File

@@ -14,6 +14,6 @@ DISCORD_IP = IP_ADDRESS
# subnet address, ex. 172.18.0.0 as we use /16.
SUBNET_ADDRESS = ADDRESS
# redis port and ip
# redis port and ip, default redis port is 6379
REDIS_IP = IP_ADDRESS
REDIS_PORT = PORT

View File

@@ -7,7 +7,7 @@ services:
build: ./ # find docker file in designated path
container_name: discord
restart: always # rebuild container always
image: kevinthedang/discord-ollama:0.8.1
image: kevinthedang/discord-ollama:0.8.2
environment:
CLIENT_TOKEN: ${CLIENT_TOKEN}
OLLAMA_IP: ${OLLAMA_IP}

8
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "discord-ollama",
"version": "0.8.1",
"version": "0.8.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "discord-ollama",
"version": "0.8.1",
"version": "0.8.2",
"license": "ISC",
"dependencies": {
"discord.js": "^14.16.3",
@@ -23,8 +23,8 @@
"vitest": "^2.1.4"
},
"engines": {
"node": ">=22.0.0",
"npm": ">=10.9.2"
"node": ">=22.12.0",
"npm": ">=10.9.0"
}
},
"node_modules/@ampproject/remapping": {

View File

@@ -1,6 +1,6 @@
{
"name": "discord-ollama",
"version": "0.8.1",
"version": "0.8.2",
"description": "Ollama Integration into discord",
"main": "build/index.js",
"exports": "./build/index.js",

View File

@@ -1,5 +1,5 @@
import { TextChannel } from 'discord.js'
import { event, Events, normalMessage, UserMessage, clean } from '../utils/index.js'
import { event, Events, normalMessage, UserMessage, clean, getTextFileAttachmentData } from '../utils/index.js'
import { getChannelInfo, getServerConfig, getUserConfig, openChannelInfo, openConfig, UserConfig, getAttachmentData } from '../utils/index.js'
/**
@@ -10,7 +10,7 @@ import { getChannelInfo, getServerConfig, getUserConfig, openChannelInfo, openCo
*/
export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client, defaultModel }, message) => {
const clientId = client.user!!.id
const cleanedMessage = clean(message.content, clientId)
let cleanedMessage = clean(message.content, clientId)
log(`Message \"${cleanedMessage}\" from ${message.author.tag} in channel/thread ${message.channelId}.`)
// Do not respond if bot talks in the chat
@@ -138,7 +138,14 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
throw new Error(`Failed to initialize User Preference for **${message.author.username}**.\n\nIt's likely you do not have a model set. Please use the \`switch-model\` command to do that.`)
// get message attachment if exists
const messageAttachment: string[] = await getAttachmentData(message.attachments.first())
const attachment = message.attachments.first()
let messageAttachment: string[] = []
if (attachment && attachment.name?.endsWith(".txt"))
cleanedMessage += await getTextFileAttachmentData(attachment)
else if (attachment)
messageAttachment = await getAttachmentData(attachment)
const model: string = userConfig.options['switch-model']
// set up new queue

View File

@@ -54,4 +54,13 @@ export async function getAttachmentData(attachment: Attachment | undefined): Pro
const buffer = await getAttachmentBuffer(url)
const base64String = arrayBufferToBase64(buffer)
return [base64String]
}
/**
* Method to retrieve the string data from the text file
*
* @param attachment the text file to convert to a string
*/
export async function getTextFileAttachmentData(attachment: Attachment): Promise<string> {
return await (await fetch(attachment.url)).text()
}