Skip to content

Commit

Permalink
Merge pull request #9 from peterdanwan/bug-fixing
Browse files Browse the repository at this point in the history
Merged lots of bug fixes
  • Loading branch information
peterdanwan authored Sep 12, 2024
2 parents ca4f24d + cdc889a commit 74c46d3
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 112 deletions.
18 changes: 14 additions & 4 deletions env.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# .env file
# .gimme_readme_config

# Reference: https://platform.openai.com/api-keys
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
# Make your OpenAI API Key: https://platform.openai.com/api-keys
OPENAI_KEY=YOUR_OPENAI_KEY

# Reference: https://aistudio.google.com/app/apikey
# Make your Gemini API Key: https://aistudio.google.com/app/apikey
GEMINI_KEY=YOUR_GEMINI_KEY

# Make your Gemini API Key: https://console.groq.com/keys
GROQ_KEY=YOUR_GROQ_KEY

# Default model you prefer to use.
# List of supported models: https://github.com/peterdanwan/gimme_readme#4-list-of-supported-models-by-providers
MODEL=llama3-8b-8192

# Default temperature you prefer to use (0-1)
TEMPERATURE=YOUR_TEMPERATURE_VALUE
239 changes: 139 additions & 100 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"commander": "^12.1.0",
"dotenv": "^16.4.5",
"groq-sdk": "^0.7.0",
"ora": "^8.1.0"
"ora": "^8.1.0",
"pkg-dir": "^8.0.0"
},
"devDependencies": {
"@eslint/js": "^9.10.0",
Expand Down
41 changes: 34 additions & 7 deletions src/_gr.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import path from 'path';
import os from 'os';
import chalk from 'chalk';
import ora from 'ora';
import { fileURLToPath } from 'url';
import {packageDirectory as pkgDir} from 'pkg-dir';

// Define __dirname for ES Modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Load .gimme_readme_config as environment variables
const configFilePath = path.join(os.homedir(), '.gimme_readme_config');
Expand All @@ -31,11 +37,26 @@ async function main() {
// Handle the config option
if (options.config) {
if (!fs.existsSync(configFilePath)) {
// Create a default config file if it doesn't exist
fs.writeFileSync(
configFilePath,
'GEMINI_KEY=your-gemini-api-key\nOPENAI_KEY=your-openai-api-key\nMODEL=gemini\nCUSTOM_PROMPT=Your custom prompt here'
);
// Find the root directory of the project
const rootDir = await pkgDir(__dirname);
if (!rootDir) {
console.error('Unable to locate the root directory of the project.');
process.exit(1);
}

// Construct the path to env.sample at the root of the project
const sampleFilePath = path.resolve(rootDir, 'env.sample');
let sampleContent;

try {
sampleContent = fs.readFileSync(sampleFilePath, 'utf-8');
} catch (err) {
console.error(`Could not find env.sample: ${err.message}`);
process.exit(1);
}

// Create a new config file with the sample content
fs.writeFileSync(configFilePath, sampleContent);
console.log(`Configuration file created at: ${chalk.blue(configFilePath)}`);
} else {
console.log(`Configuration file located at: ${chalk.blue(configFilePath)}`);
Expand All @@ -54,11 +75,17 @@ async function main() {
// Let the user specify their own prompt, or use the prompt that we have engineered
let prompt = options.prompt || process.env.CUSTOM_PROMPT || defaultPrompt;
const model = options.model || process.env.MODEL || 'gemini-1.5-flash';
const outputFile = options.outputFile || null;
const temperature = options.temperature || null;
const outputFile = options.outputFile || process.env.OUTPUT_FILE || null;
const temperature = options.temperature || process.env.TEMPERATURE || null;

const validFiles = [];

// Check if files is an array and has at least one entry
if (!Array.isArray(files)) {
console.log("error: option '-f, --file [files...]' argument missing ");
process.exit(1);
}

for (const file of files) {
try {
const content = getFileContent(file);
Expand Down

0 comments on commit 74c46d3

Please sign in to comment.