I know this is and old thread, but I am facing the same issue here.
I found a way to split long messages that are longer than the length limit but still unable to solve the issue when the assistant calls multiple function.
I have tried to output submitTool for each call, but the API expect all tool_ouputs.
If this can help anyone, here is my code to send large amount of data over messages.
/**
* Splits a string into chunks of specified maximum length.
* @function
* @name OpenAIService#splitIntoChunks
* @param {String} inputString - The string to be split.
* @param {number} maxLength - The maximum length of each chunk.
* @returns {Array<String>} - An array of string chunks.
*/
splitIntoChunks(inputString, maxLength) {
const chunks = [];
let startIndex = 0;
while (startIndex < inputString.length) {
chunks.push(inputString.slice(startIndex, startIndex + maxLength));
startIndex += maxLength;
}
return chunks;
}
//Usage
const content = JSON.stringify(payload);
if(content.length > 256000){
const chunks = this.splitIntoChunks(content, 250000);
await this.createMessage('user', `The data will be sent over multiple message. Wait for the """DONE""" than concatenate all messages excluding this one and the final one. Use the concatenate message as the data you need to analyse.`);
for(const chunk of chunks){
await this.createMessage('user', chunk)
}
await this.createMessage('user', `"""DONE"""`)
}else{
await this.createMessage('user', content);
}