getTokenCountForMessage(message) {
        let tokensPerMessage;
        let nameAdjustment;
        if (this.modelOptions.model.startsWith('gpt-4')) {
            tokensPerMessage = 3;
            nameAdjustment = 1;
        } else {
            tokensPerMessage = 4;
            nameAdjustment = -1;
        }

        // Map each property of the message to the number of tokens it contains
        const propertyTokenCounts = Object.entries(message).map(([key, value]) => {
            // Count the number of tokens in the property value
            const numTokens = this.getTokenCount(value);

            // Adjust by `nameAdjustment` tokens if the property key is 'name'
            const adjustment = (key === 'name') ? nameAdjustment : 0;
            return numTokens + adjustment;
        });

        // Sum the number of tokens in all properties and add `tokensPerMessage` for metadata
        return propertyTokenCounts.reduce((a, b) => a + b, tokensPerMessage);
    }
Algorithm adapted from "6. Counting tokens for chat API calls" of
https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb

An additional 2 tokens need to be added for metadata after all messages have been counted.

@param {*} message