Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jhcoll committed Oct 25, 2023
1 parent 05572be commit af2155c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/generate-related/compute-embeddings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { markdownToTxt } = require("markdown-to-txt");
const filename = `${outputPath}/${file}`;

if (!fs.existsSync(filename)) {
await summarisePost(formatContent(path)).then((embedding) => {
await summarisePost(formatContent(path), file).then((embedding) => {
fs.writeFileSync(filename, JSON.stringify(embedding, null, 2));
});
}
Expand All @@ -36,7 +36,7 @@ const formatContent = (post) => {
return text.split(/[\s]+/).slice(0, 1000).join(" ");
};

const summarisePost = async (data) => {
const summarisePost = async (data, file) => {
const OPENAI_API_KEY = process.env.npm_config_openai_api_key;

return await fetch(
Expand All @@ -54,11 +54,13 @@ const summarisePost = async (data) => {
})
.then((res) => {
if(res.status !== 200) {
console.log("failed to embed: " + file)
if(res.status === 401) {
throw Error(res.statusText + " - check your OpenAI API key");
}
throw Error(res.statusText);
}
return res.json()
})
.then((json) => {
if (json.data) {
Expand Down

0 comments on commit af2155c

Please sign in to comment.