async handleStream(response, stream, responseProps) {
    return new Promise(async (resolve) => {
      const { uuid = v4(), sources = [] } = responseProps;
      let fullText = "";
      let usage = {
        prompt_tokens: 0,
        completion_tokens: 0,
      };

      const handleAbort = () => {
        writeResponseChunk(response, {
          uuid,
          sources,
          type: "abort",
          textResponse: fullText,
          close: true,
          error: false,
        });
        response.removeListener("close", handleAbort);
        stream.endMeasurement(usage);
        resolve(fullText);
      };
      response.on("close", handleAbort);

      try {
        for await (const chat of stream) {
          if (chat.eventType === "stream-end") {
            const usageMetrics = chat?.response?.meta?.tokens || {};
            usage.prompt_tokens = usageMetrics.inputTokens || 0;
            usage.completion_tokens = usageMetrics.outputTokens || 0;
          }

          if (chat.eventType === "text-generation") {
            const text = chat.text;
            fullText += text;

            writeResponseChunk(response, {
              uuid,
              sources,
              type: "textResponseChunk",
              textResponse: text,
              close: false,
              error: false,
            });
          }
        }

        writeResponseChunk(response, {
          uuid,
          sources,
          type: "textResponseChunk",
          textResponse: "",
          close: true,
          error: false,
        });
        response.removeListener("close", handleAbort);
        stream.endMeasurement(usage);
        resolve(fullText);
      } catch (error) {
        writeResponseChunk(response, {
          uuid,
          sources,
          type: "abort",
          textResponse: null,
          close: true,
          error: error.message,
        });
        response.removeListener("close", handleAbort);
        stream.endMeasurement(usage);
        resolve(fullText);
      }
    });
  }
Handles the stream response from the Cohere API.
@param {Object} response - the response object
@param {import('../../helpers/chat/LLMPerformanceMonitor').MonitoredStream} stream - the stream response from the Cohere API w/tracking
@param {Object} responseProps - the response properties
@returns {Promise<string>}