Skip to content

Commit

Permalink
Ensured .message existence before checking .message.author.role i…
Browse files Browse the repository at this point in the history
…n `.getChatData().getChatMsgs()` (#177) ↞ [auto-sync from `KudoAI/chatgpt.js`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed May 1, 2024
1 parent 8365885 commit 995a12a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions starters/chrome/extension/lib/chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ const chatgpt = { // eslint-disable-line no-redeclare

// Fill [userMessages]
for (const key in data)
if ('message' in data[key] && data[key].message.author.role == 'user')
if (data[key].message != null && data[key].message.author.role == 'user')
userMessages.push({ id: data[key].id, msg: data[key].message });
userMessages.sort((a, b) => a.msg.create_time - b.msg.create_time); // sort in chronological order

Expand All @@ -808,7 +808,7 @@ const chatgpt = { // eslint-disable-line no-redeclare
for (const userMessage of userMessages) {
let sub = [];
for (const key in data) {
if ('message' in data[key] && data[key].message.author.role == 'assistant' && data[key].parent == userMessage.id) {
if (data[key].message != null && data[key].message.author.role == 'assistant' && data[key].parent == userMessage.id) {
sub.push(data[key].message);
}
}
Expand Down

0 comments on commit 995a12a

Please sign in to comment.