Skip to content

Commit

Permalink
Infinite Message Length for Streamed Messages (#70)
Browse files Browse the repository at this point in the history
* Add: Infinite Stream messages

* Update: version increment
  • Loading branch information
kevinthedang authored Jun 17, 2024
1 parent 89213c2 commit 32b12e9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
build: ./ # find docker file in designated path
container_name: discord
restart: always # rebuild container always
image: discord/bot:0.5.0
image: discord/bot:0.5.1
environment:
CLIENT_TOKEN: ${CLIENT_TOKEN}
GUILD_ID: ${GUILD_ID}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-ollama",
"version": "0.5.0",
"version": "0.5.1",
"description": "Ollama Integration into discord",
"main": "build/index.js",
"exports": "./build/index.js",
Expand Down
26 changes: 15 additions & 11 deletions src/utils/messageNormal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,23 @@ export async function normalMessage(

// run query based on stream preference, true = stream, false = block
if (stream) {
response = await streamResponse(params)
let messageBlock: Message = sentMessage
response = await streamResponse(params) // THIS WILL BE SLOW due to discord limits!
for await (const portion of response) {
// append token to message
result += portion.message.content
// check if over discord message limit
if (result.length + portion.message.content.length > 2000) {
result = portion.message.content

// exceeds handled length
if (result.length > 2000) {
message.channel.send(`Response length ${result.length} has exceeded Discord maximum.\n\nLong Stream messages not supported.`)
break // stop stream
}

// resent current output, THIS WILL BE SLOW due to discord limits!
sentMessage.edit(result || 'No Content Yet...')
// new message block, wait for it to send and assign new block to respond.
await message.channel.send("Creating new stream block...").then(sentMessage => { messageBlock = sentMessage })
} else {
result += portion.message.content

// ensure block is not empty
if (result.length > 5)
messageBlock.edit(result)
}
console.log(result)
}
}
else {
Expand Down

0 comments on commit 32b12e9

Please sign in to comment.