This is a simple Node.js command-line application that demonstrates how to use the Azure OpenAI service with the openai JavaScript library.
- Node.js (v18+ recommended)
- An Azure account with an active subscription.
- An Azure OpenAI Service resource deployed with a model (e.g.,
gpt-35-turbo).
-
Install dependencies:
Using npm, install the required packages listed in
package.json.npm install
-
Configure Environment Variables:
Create a
.envfile in the root of the project. This file will store your Azure OpenAI credentials. Add the following content to it, replacing the placeholder values with your specific details.AZURE_OPENAI_ENDPOINT="<YOUR_AZURE_OPENAI_ENDPOINT>" AZURE_OPENAI_API_KEY="<YOUR_AZURE_OPENAI_API_KEY>" MODEL_NAME="<YOUR_DEPLOYMENT_NAME>"
Execute the script from your terminal using node. Pass your prompt as a command-line argument enclosed in quotes.
node run_model.js "Your prompt here"