Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom .env file location via CLI/env #856

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions docs/src/content/docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ the `.env` file will appear grayed out in Visual Studio Code.

:::

### Custom .env file location

You can specify a custom `.env` file location.

- by adding the `--env <file>` argument to the CLI.

```sh "--env .env.local"
npx genaiscript ... --env .env.local
```

- by setting the `GENAISCRIPT_ENV_FILE` environment variable.

```sh
GENAISCRIPT_ENV_FILE=.env.local npx genaiscript ...
```

## OpenAI

This provider, `openai`, is the OpenAI chat model provider.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
process.on("uncaughtException", (err) => {
const se = serializeError(err) // Serialize the error object
error(errorMessage(se)) // Log the error message
if (!isQuiet && se?.stack) logVerbose(se?.stack) // Log stack trace if not in quiet mode
if (!isQuiet && se?.stack && nodeHost) logVerbose(se?.stack) // Log stack trace if not in quiet mode

Check failure on line 59 in packages/cli/src/cli.ts

View workflow job for this annotation

GitHub Actions / build

The variable `nodeHost` is used without being defined or imported in this context. Ensure that `nodeHost` is properly defined or imported before use. 🧐
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
if (isRequestError(err)) {
const exitCode = (err as RequestError).status // Use the error status as exit code
process.exit(exitCode) // Exit with the error status code
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/nodehost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@
}

static async install(dotEnvPath: string) {
dotEnvPath = dotEnvPath || resolve(DOT_ENV_FILENAME)
dotEnvPath = dotEnvPath || process.env.GENAISCRIPT_ENV_FILE
if (dotEnvPath) {
// if the user provided a path, check file existence
if (!(await exists(dotEnvPath)))

Check failure on line 182 in packages/cli/src/nodehost.ts

View workflow job for this annotation

GitHub Actions / build

The `exists` function is awaited, but it is not clear if it returns a Promise. Ensure that `exists` is an asynchronous function returning a Promise. If not, remove the `await` keyword. πŸ”

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exists function is awaited, but it is not clear if it returns a Promise. Ensure that exists is an asynchronous function returning a Promise. If not, remove the await keyword. πŸ”

generated by pr-review-commit async_await_misuse

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exists function is used as if it returns a promise, but it's not clear if it is an async function. Ensure that exists is an async function or handle it appropriately.

generated by pr-review-commit async_function

pelikhan marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`.env file not found at ${dotEnvPath}`)

Check failure on line 183 in packages/cli/src/nodehost.ts

View workflow job for this annotation

GitHub Actions / build

Throwing a generic `Error` with a string message can make debugging difficult. Consider creating a custom error class for more context or using a more descriptive error message. πŸ’‘
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
} else {
dotEnvPath = resolve(DOT_ENV_FILENAME)
}
const h = new NodeHost(dotEnvPath)
setRuntimeHost(h)
await h.parseDefaults()
Expand Down
Loading