Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

refactor: several tiny improvements #20

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@ typings/
# dotenv environment variables file
.env

# next.js build output
.next
8 changes: 6 additions & 2 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ async function createChatGPTAPI(sessionToken) {
return api;
}

function is503Error(err) {
return toString(err).includes("503");
}

async function callChatGPT(api, content, retryOn503) {
let cnt = 0;
while (cnt++ <= retryOn503) {
try {
const response = await api.sendMessage(content);
return response;
} catch (err) {
if (!toString(err).includes("503")) throw err;
if (!is503Error(err)) throw err;
}
}
}
Expand All @@ -34,7 +38,7 @@ async function startConversation(api, retryOn503) {
const response = await conversation.sendMessage(message);
return response;
} catch (err) {
if (!toString(err).includes("503")) throw err;
if (!is503Error(err)) throw err;
}
}
},
Expand Down