Skip to content
Snippets Groups Projects
Commit 587960ae authored by Marcus Schiesser's avatar Marcus Schiesser
Browse files

fix: use dotenv for npm run generate, use `.env` for NextJS, fix package versions for pnpm

parent 4e1b6784
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,8 @@ import {
VectorStoreIndex,
} from "llamaindex";
import * as dotenv from "dotenv";
import {
CHUNK_OVERLAP,
CHUNK_SIZE,
......@@ -12,6 +14,9 @@ import {
STORAGE_DIR,
} from "./constants.mjs";
// Load environment variables from local .env file
dotenv.config();
async function getRuntime(func) {
const start = Date.now();
await func();
......
......@@ -14,26 +14,14 @@ import {
TemplateFramework,
} from "./types";
const envFileNameMap: Record<TemplateFramework, string> = {
nextjs: ".env.local",
express: ".env",
fastapi: ".env",
};
const createEnvLocalFile = async (
root: string,
framework: TemplateFramework,
openAIKey?: string,
) => {
const createEnvLocalFile = async (root: string, openAIKey?: string) => {
if (openAIKey) {
const envFileName = envFileNameMap[framework];
if (!envFileName) return;
const envFileName = ".env";
await fs.writeFile(
path.join(root, envFileName),
`OPENAI_API_KEY=${openAIKey}\n`,
);
console.log(`Created '${envFileName}' file containing OPENAI_API_KEY`);
process.env["OPENAI_API_KEY"] = openAIKey;
}
};
......@@ -42,6 +30,7 @@ const copyTestData = async (
framework: TemplateFramework,
packageManager?: PackageManager,
engine?: TemplateEngine,
openAIKey?: string,
) => {
if (engine === "context" || framework === "fastapi") {
const srcPath = path.join(__dirname, "components", "data");
......@@ -54,7 +43,7 @@ const copyTestData = async (
}
if (packageManager && engine === "context") {
if (process.env["OPENAI_API_KEY"]) {
if (openAIKey || process.env["OPENAI_API_KEY"]) {
console.log(
`\nRunning ${cyan(
`${packageManager} run generate`,
......@@ -313,7 +302,7 @@ export const installTemplate = async (
// This is a backend, so we need to copy the test data and create the env file.
// Copy the environment file to the target directory.
await createEnvLocalFile(props.root, props.framework, props.openAIKey);
await createEnvLocalFile(props.root, props.openAIKey);
// Copy test pdf file
await copyTestData(
......@@ -321,6 +310,7 @@ export const installTemplate = async (
props.framework,
props.packageManager,
props.engine,
props.openAIKey,
);
}
};
......
......@@ -9,6 +9,7 @@
},
"dependencies": {
"llamaindex": "0.0.31",
"dotenv": "^16.3.1",
"nanoid": "^5",
"next": "^13",
"react": "^18",
......@@ -18,11 +19,11 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10",
"autoprefixer": "^10.1",
"eslint": "^8",
"eslint-config-next": "^13",
"postcss": "^8",
"tailwindcss": "^3",
"tailwindcss": "^3.3",
"typescript": "^5"
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@
"dev": "concurrently \"tsup index.ts --format esm --dts --watch\" \"nodemon -q dist/index.js\""
},
"dependencies": {
"ai": "^2",
"ai": "^2.2.5",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4",
......@@ -25,4 +25,4 @@
"tsup": "^7",
"typescript": "^5"
}
}
}
\ No newline at end of file
......@@ -8,8 +8,9 @@
"lint": "next lint"
},
"dependencies": {
"ai": "^2",
"ai": "^2.2.5",
"llamaindex": "0.0.31",
"dotenv": "^16.3.1",
"next": "^13",
"react": "^18",
"react-dom": "^18"
......@@ -18,11 +19,11 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10",
"autoprefixer": "^10.1",
"eslint": "^8",
"eslint-config-next": "^13",
"postcss": "^8",
"tailwindcss": "^3",
"tailwindcss": "^3.3",
"typescript": "^5"
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment