Mintplex-Labs / anything-llm

The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, and more.
https://anythingllm.com
MIT License
27.9k stars 2.83k forks source link

Bug (Showstopper type): TypeError: tokenChunks.slice is not a function #541

Closed pritchey closed 11 months ago

pritchey commented 11 months ago

The following entry in the Docker log output provides the clue:

2024-01-05 12:22:08 TypeError: tokenChunks.slice is not a function 2024-01-05 12:22:08 at cannonball (/app/server/utils/helpers/chat/index.js:307:34) 2024-01-05 12:22:08 at /app/server/utils/helpers/chat/index.js:143:29 2024-01-05 12:22:08 at new Promise () 2024-01-05 12:22:08 at messageArrayCompressor (/app/server/utils/helpers/chat/index.js:102:29) 2024-01-05 12:22:08 at LMStudioLLM.compressMessages (/app/server/utils/AiProviders/lmStudio/index.js:187:18) 2024-01-05 12:22:08 at streamChatWithWorkspace (/app/server/utils/chats/stream.js:98:39) 2024-01-05 12:22:08 at async /app/server/endpoints/chat.js:76:9

Looking at the file /app/server/utils/helpers/chat/index.js, specifically line 307 shows this:

const leftChunks = tokenChunks.slice(0, middleIdx - Math.round(delta / 2));

Digging backwards through the code, the tokenChunks is an integer value, not an array, therefore doesn't support the slice method to split the array into parts.

timothycarambat commented 11 months ago

Great catch, that was my fault. Will need to start building tests around those methods to prevent this