How to use environment variables to configure the AI prompt exe

If you work with Ozeki AI prompt to execute AI requests as a command line arg or by passing it to the std in, you might want to simplify he usage by using environment variables. This guide explains how you can use environment variables to configure the AIPrompt executable. Let's get started!

What are environment variables?

Environment variables are key-value pairs used by operating systems and applications to store configuration data. They provide a way to customize and control the behavior of processes without modifying code. They are particularly useful when you need to set configurations that are consistent across multiple runs or systems. For instance, they allow sensitive information, such as API keys or passwords, to be stored securely without hardcoding them into the application or passing them as command-line arguments.

Using environment variables to configure AI Prompt

Use the environment variables specified belwo to configure your preferences. The app supports all Environment Variable Scopes for Windows. If the same key is specified in multiple scopes, then order of evaluation is Process, User, and Machine.

Key Usage Accepted Values
OZEKI_AIPROMPT_URL Specifies the URL of the server URLs with http or https scheme
OZEKI_AIPROMPT_USERNAME Specifies the username for authentication string
OZEKI_AIPROMPT_PASSWORD Specifies the password for authentication string
OZEKI_AIPROMPT_APIKEY Specifies the API key string
OZEKI_AIPROMPT_USE_JSON Specifies if the prompt is in JSON format True, False
OZEKI_AIPROMPT_MODEL Specifies the model name string

Working with environment variables on the command line

How to setup environment variables on the command line

To set an environment variable on the commandline, use the set command:

set key=value

For example:

set OZEKI_AIPROMPT_USERNAME=username

The environment variable is set
Figure 1 - The environment variable is set

The set command ran successfully, but the Command Prompt did not print any feedback (Figure 1). Continue to the next step to learn how to check the value of an environment variable.

How to check if an environment variable is set on the command line

To check if an environment variable is set, use the set command with key of the variable you are looking for on the command line:

set key

To continue with the previous example:

set OZEKI_AIPROMPT_USERNAME

Environment variable is set
Figure 2 - Environment variable was set beforehand

Output:

OZEKI_AIPROMPT_USERNAME=username

Check an environment variable, which does not have a value:

set OZEKI_AIPROMPT_API

Environment variable is not specified
Figure 3 - Environment variable is not specified

Output:

Environment variable OZEKI_AIPROMPT_APIKEY not defined

How to list environment variables on the command line

To get the list of all environment variables on the commandline, use the set command without any parameters:

All environment variables listed
Figure 4 - List all environment variables

The set command without parameters shows all environment variables, even the ones not configuring the AI Prompt. To print environment variables set for the AI Prompt, use the following command:

set OZEKI_AIPROMPT

If all AI Prompt environment variables are set, the output will look like this:

Only AI Prompt environment variables listed
Figure 5 - List only the AI Prompt related environment variables

Output:

OZEKI_AIPROMPT_APIKEY=apikey
OZEKI_AIPROMPT_MODEL=AI
OZEKI_AIPROMPT_PASSWORD=password
OZEKI_AIPROMPT_URL=http://localhost:9511/api?command=chatgpt
OZEKI_AIPROMPT_USERNAME=username
OZEKI_AIPROMPT_USE_JSON=true

How to run AI Prompt using environment variables (Quick steps)

  1. Set environment variables
  2. Confirm environment variables
  3. Run AI Prompt with environment variables

How to run AI Prompt using environment variables (Video tutorial)

Watch this video to learn how to set your AI Prompt configuration with environment variables, check if you correctly set them, then run AI Prompt with this configuration. Type in the commands to your command prompt or you can also paste them with Ctrl+V.

Video 6 - Run AI Prompt with environment variables

Set environment variables

The environment variables must be set before running the aiprompt.exe. In the following example, we will send a request with a HTTP User. Let's see an example:

::Change the values to your own configuration
set OZEKI_AIPROMPT_USERNAME=user
set OZEKI_AIPROMPT_PASSWORD=pass
set OZEKI_AIPROMPT_URL=http://localhost:9509/api?command=chatgpt
set OZEKI_AIPROMPT_MODEL=GGUF_Model_1

You can either type in or copy and paste the commands to the Command Prompt. To paste a command, first copy it, then paste it to the Command Prompt by pressing the Ctrl+V key combination.

Set environment variables
Figure 7 - Set environment variables

Confirm environment variables

Check if the environment variables are set successfully:

set OZEKI_AIPROMPT

Confirm environment variables
Figure 8 - Confirm environment variables

Output:

OZEKI_AIPROMPT_MODEL=GGUF_Model_1
OZEKI_AIPROMPT_PASSWORD=pass
OZEKI_AIPROMPT_URL=http://localhost:9509/api?command=chatgpt
OZEKI_AIPROMPT_USERNAME=user

Run AI Prompt

Because we already specified the credentials and the AI model with environment variables, only the prompt has to be given:

aiprompt.exe "What is the capital of Hungary"

If the variables were set properly, you should get a response from the HTTP API:

Run AI Prompt with environment variables
Figure 9 - Run AI Prompt with environment variables

Output:

Role: assistant
Content: The capital of Hungary is Budapest.

Why did my environment variables disappear after closing the command prompt?

Environment variables set in the command prompt are temporary and only apply to the current session. When the command prompt window is closed, all variables set in that session are discarded. This behavior ensures that changes made to the ,environment do not persist and potentially affect other sessions or processes.

Can I permanently set an environment variable?

Yes, you can permanently set an environment variables, but this is not recommended because it could affect other AI Prompt sessions configuration as well. If you need to persist configurations in environment variables, the recommended way is to set the variables and run the AI Prompt from a shell script (batch on Windows, bash on Linux or MacOS).

If you are really sure that you want to permanently set your environment variables, you can set them in the System Properties window on Windows. Alternatively, you can use the setx command in the command prompt to permanently set a variable.

Conclusion

Using environment variables to configure the AI Prompt executable simplifies the process of setting up and managing your configurations. Whether you are working locally or on multiple systems, environment variables provide a consistent and efficient way to enhance your productivity with AI Prompt. Start using these techniques today to optimize your experience!

More information