nyegosh
Version:
AI generated commit messages, like Njegoš wrote them.
79 lines (64 loc) • 2.95 kB
JavaScript
const fs = require("fs");
const path = require("path");
const { promptUser } = require("./lib/readline");
const connectionType = process.argv.slice(2);
const envPath = path.join(require("os").homedir(), ".nyegosh.env");
const defaultModel = "gpt-4o-mini";
async function connectAzure() {
console.log("\nWelcome to the Nyegosh installation wizard!");
console.log("We'll configure the environment variables needed for the package.\n");
try {
const apiKey = await promptUser("Enter your Azure OpenAI API key: ");
const apiEndpoint = await promptUser(
"Enter your Azure OpenAI endpoint (e.g., https://your-resource-name.openai.azure.com): ",
);
const deployment = await promptUser("Enter your generator deployment name:", defaultModel);
const apiVersion = await promptUser("Enter your generator API version:", "2024-08-01-preview");
const envContent = [
`NYEGOSH_CONNECTION_TYPE=azure`,
`NYEGOSH_AZURE_OPENAI_API_VERSION=${apiVersion}`,
`NYEGOSH_AZURE_OPENAI_API_KEY=${apiKey}`,
`NYEGOSH_AZURE_OPENAI_ENDPOINT=${apiEndpoint}`,
`NYEGOSH_GENERATOR_DEPLOYMENT=${deployment}`,
].join("\n");
fs.writeFileSync(envPath, envContent);
console.log(`\nEnvironment variables have been saved to ${envPath}`);
console.log("You can edit this file later to update the configuration.");
console.log("Installation complete! Happy coding!\n");
} catch (err) {
console.error("\nAn error occurred while saving the configuration:", err.message);
}
}
async function connectOpenAI() {
console.log("\nWelcome to the Nyegosh installation wizard!");
console.log("We'll configure the environment variables needed for the package.\n");
try {
const apiKey = await promptUser("Enter your OpenAI API key: ");
const deployment = await promptUser("Enter your generator deployment name: ", defaultModel);
const envContent = [
`NYEGOSH_CONNECTION_TYPE=openai`,
`NYEGOSH_GENERATOR_DEPLOYMENT=${deployment}`,
`NYEGOSH_OPENAI_API_KEY=${apiKey}`,
].join("\n");
fs.writeFileSync(envPath, envContent);
console.log(`\nEnvironment variables have been saved to ${envPath}`);
console.log("You can edit this file later to update the configuration.");
console.log("Installation complete! Happy coding!\n");
} catch (err) {
console.error("\nAn error occurred while saving the configuration:", err.message);
}
}
(async () => {
switch (connectionType[0]) {
case "azure":
connectAzure();
break;
case "openai":
connectOpenAI();
break;
default:
console.error("Invalid connection type. Please specify either 'azure' or 'openai'.");
process.exit(1);
}
})();