Infinite Message Length for Block Messages (#55)
* add: message loop for block messages * add: infinite message length for block embeds * update: error message on stream length * rm: unnecessary import * update: version increment * update: embed max length * update: check off features
This commit is contained in:
@@ -16,9 +16,9 @@ The project aims to:
|
|||||||
* [x] Containerization with Docker
|
* [x] Containerization with Docker
|
||||||
* [x] Slash Commands Compatible
|
* [x] Slash Commands Compatible
|
||||||
* [x] Generated Token Length Handling for >2000 ~~or >6000 characters~~
|
* [x] Generated Token Length Handling for >2000 ~~or >6000 characters~~
|
||||||
* [ ] Token Length Handling of any message size
|
* [x] Token Length Handling of any message size
|
||||||
* [ ] External WebUI Integration
|
* [ ] External WebUI Integration
|
||||||
* [ ] Administrator Role Compatible
|
* [x] Administrator Role Compatible
|
||||||
* [ ] Allow others to create their own models personalized for their own servers!
|
* [ ] Allow others to create their own models personalized for their own servers!
|
||||||
* [ ] Documentation on creating your own LLM
|
* [ ] Documentation on creating your own LLM
|
||||||
* [ ] Documentation on web scrapping and cleaning
|
* [ ] Documentation on web scrapping and cleaning
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ services:
|
|||||||
build: ./ # find docker file in designated path
|
build: ./ # find docker file in designated path
|
||||||
container_name: discord
|
container_name: discord
|
||||||
restart: always # rebuild container always
|
restart: always # rebuild container always
|
||||||
image: discord/bot:0.4.3
|
image: discord/bot:0.4.4
|
||||||
environment:
|
environment:
|
||||||
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
||||||
GUILD_ID: ${GUILD_ID}
|
GUILD_ID: ${GUILD_ID}
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.4.3",
|
"version": "0.4.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.4.3",
|
"version": "0.4.4",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.14.1",
|
"discord.js": "^14.14.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.4.3",
|
"version": "0.4.4",
|
||||||
"description": "Ollama Integration into discord",
|
"description": "Ollama Integration into discord",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"exports": "./build/index.js",
|
"exports": "./build/index.js",
|
||||||
|
|||||||
@@ -47,27 +47,72 @@ export async function embedMessage(
|
|||||||
for await (const portion of response) {
|
for await (const portion of response) {
|
||||||
result += portion.message.content
|
result += portion.message.content
|
||||||
|
|
||||||
|
// exceeds handled length
|
||||||
|
if (result.length > 5000) {
|
||||||
|
const errorEmbed = new EmbedBuilder()
|
||||||
|
.setTitle(`Responding to ${message.author.tag}`)
|
||||||
|
.setDescription(`Response length ${result.length} has exceeded Discord maximum.\n\nLong Stream messages not supported.`)
|
||||||
|
.setColor('#00FF00')
|
||||||
|
|
||||||
|
// send error
|
||||||
|
message.channel.send({ embeds: [errorEmbed] })
|
||||||
|
break // cancel loop and stop
|
||||||
|
}
|
||||||
|
|
||||||
// new embed per token...
|
// new embed per token...
|
||||||
const newEmbed = new EmbedBuilder()
|
const streamEmbed = new EmbedBuilder()
|
||||||
.setTitle(`Responding to ${message.author.tag}`)
|
.setTitle(`Responding to ${message.author.tag}`)
|
||||||
.setDescription(result || 'No Content Yet...')
|
.setDescription(result || 'No Content Yet...')
|
||||||
.setColor('#00FF00')
|
.setColor('#00FF00')
|
||||||
|
|
||||||
// edit the message
|
// edit the message
|
||||||
sentMessage.edit({ embeds: [newEmbed] })
|
sentMessage.edit({ embeds: [streamEmbed] })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
response = await blockResponse(params)
|
response = await blockResponse(params)
|
||||||
result = response.message.content
|
result = response.message.content
|
||||||
|
|
||||||
// only need to create 1 embed again
|
// long message, split into different embeds sadly.
|
||||||
const newEmbed = new EmbedBuilder()
|
if (result.length > 5000) {
|
||||||
.setTitle(`Responding to ${message.author.tag}`)
|
const firstEmbed = new EmbedBuilder()
|
||||||
.setDescription(result || 'No Content to Provide...')
|
.setTitle(`Responding to ${message.author.tag}`)
|
||||||
.setColor('#00FF00')
|
.setDescription(result.slice(0, 5000) || 'No Content to Provide...')
|
||||||
|
.setColor('#00FF00')
|
||||||
|
|
||||||
// edit the message
|
// replace first embed
|
||||||
sentMessage.edit({ embeds: [newEmbed] })
|
sentMessage.edit({ embeds: [firstEmbed] })
|
||||||
|
|
||||||
|
// take the rest out
|
||||||
|
result = result.slice(5000)
|
||||||
|
|
||||||
|
// handle the rest
|
||||||
|
while (result.length > 5000) {
|
||||||
|
const whileEmbed = new EmbedBuilder()
|
||||||
|
.setTitle(`Responding to ${message.author.tag}`)
|
||||||
|
.setDescription(result.slice(0, 5000) || 'No Content to Provide...')
|
||||||
|
.setColor('#00FF00')
|
||||||
|
|
||||||
|
message.channel.send({ embeds: [whileEmbed] })
|
||||||
|
result = result.slice(5000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastEmbed = new EmbedBuilder()
|
||||||
|
.setTitle(`Responding to ${message.author.tag}`)
|
||||||
|
.setDescription(result || 'No Content to Provide...')
|
||||||
|
.setColor('#00FF00')
|
||||||
|
|
||||||
|
// rest of the response
|
||||||
|
message.channel.send({ embeds: [lastEmbed] })
|
||||||
|
} else {
|
||||||
|
// only need to create 1 embed, handles 6000 characters
|
||||||
|
const newEmbed = new EmbedBuilder()
|
||||||
|
.setTitle(`Responding to ${message.author.tag}`)
|
||||||
|
.setDescription(result || 'No Content to Provide...')
|
||||||
|
.setColor('#00FF00')
|
||||||
|
|
||||||
|
// edit the message
|
||||||
|
sentMessage.edit({ embeds: [newEmbed] })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch(error: any) {
|
} catch(error: any) {
|
||||||
console.log(`[Util: messageEmbed] Error creating message: ${error.message}`)
|
console.log(`[Util: messageEmbed] Error creating message: ${error.message}`)
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ export async function normalMessage(
|
|||||||
// append token to message
|
// append token to message
|
||||||
result += portion.message.content
|
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!
|
// resent current output, THIS WILL BE SLOW due to discord limits!
|
||||||
sentMessage.edit(result || 'No Content Yet...')
|
sentMessage.edit(result || 'No Content Yet...')
|
||||||
}
|
}
|
||||||
@@ -49,8 +55,17 @@ export async function normalMessage(
|
|||||||
// check if message length > discord max for normal messages
|
// check if message length > discord max for normal messages
|
||||||
if (result.length > 2000) {
|
if (result.length > 2000) {
|
||||||
sentMessage.edit(result.slice(0, 2000))
|
sentMessage.edit(result.slice(0, 2000))
|
||||||
message.channel.send(result.slice(2000))
|
result = result.slice(2000)
|
||||||
} else // edit the 'generic' response to new message
|
|
||||||
|
// handle for rest of message that is >2000
|
||||||
|
while (result.length > 2000) {
|
||||||
|
message.channel.send(result.slice(0, 2000))
|
||||||
|
result = result.slice(2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// last part of message
|
||||||
|
message.channel.send(result)
|
||||||
|
} else // edit the 'generic' response to new message since <2000
|
||||||
sentMessage.edit(result)
|
sentMessage.edit(result)
|
||||||
}
|
}
|
||||||
} catch(error: any) {
|
} catch(error: any) {
|
||||||
@@ -59,6 +74,6 @@ export async function normalMessage(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// return the string representation of response
|
// return the string representation of ollama query response
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user