dto-btn / ssc-assistant

Second iteration of the SSC chatbot/assistant
MIT License
0 stars 0 forks source link

[bug] Not able to stream on Safari #123

Open GuillaumeTurcotte opened 1 month ago

GuillaumeTurcotte commented 1 month ago

This bit of code from api.ts doesn't work on Safari (on mac os):

  try {
    while (true) {
      const { done, value } = await reader.read();
      if (done) break;

      partialData += decoder.decode(value, { stream: true });
      const result = contentRegex.exec(partialData);
      if(result && result[1]) {
        const content = result[1].trim();
        updateLastMessage(content);
      }
    }

    //finished reading the stream, let's load the json object properly this time and populate the rest of the answer.
    const json = jsonRegex.exec(partialData);
    if(json && json[1]){
      completion = JSON.parse(json[1]);
    }

    if (!completion) {
      throw new Error('Failed to obtain completion from the server response.');
    }
  } catch (error) {
    console.error('Error while reading the stream:', error);
    throw error;
  } finally {
    reader.releaseLock();
  }

  return completion;
}

image (9) loadfailed

success criteria

GuillaumeTurcotte commented 1 month ago

TDB; this might have to do with headers sent (badly formatted ones).