Add: Filter out think tags in bot message (#190)

This commit is contained in:
Kevin Dang
2025-10-04 20:17:26 -07:00
committed by GitHub
parent c00ea5de98
commit 32137dacb0
4 changed files with 12 additions and 4 deletions

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.6
image: kevinthedang/discord-ollama:0.8.7
environment:
CLIENT_TOKEN: ${CLIENT_TOKEN}
OLLAMA_IP: ${OLLAMA_IP}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "discord-ollama",
"version": "0.8.5",
"version": "0.8.7",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "discord-ollama",
"version": "0.8.5",
"version": "0.8.7",
"license": "ISC",
"dependencies": {
"discord.js": "^14.20.0",

View File

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

View File

@@ -56,6 +56,10 @@ export async function normalMessage(
response = await blockResponse(params)
result = response.message.content
// check if there is a <think>...</think> sequence from the bot.
if (hasThinking(result))
result = result.replace(/<think>[\s\S]*?<\/think>/g, '').trim()
// check if message length > discord max for normal messages
if (result.length > 2000) {
sentMessage.edit(result.slice(0, 2000))
@@ -85,3 +89,7 @@ export async function normalMessage(
// return the string representation of ollama query response
return result
}
function hasThinking(message: string): boolean {
return /<think>[\s\S]*?<\/think>/i.test(message)
}