Skip to content

IT-HUSET/azure-openai-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Azure OpenAI Command Line Tools

Simple command-line tools for Azure OpenAI in both Python and JavaScript/Deno.

Project Structure

.
├── .env           # Shared Azure OpenAI credentials
├── python/        # Python implementation
│   ├── ask.py     # One-shot query tool
│   └── chat.py    # Interactive chat
└── js/            # JavaScript/Deno implementation
    ├── ask.js     # One-shot query tool
    └── chat.js    # Interactive chat

Prerequisites

  • Python version: Python >= 3.13 with uv installed
  • Deno version: Deno >= 1.40
  • Azure OpenAI resource with a deployed model

Setup

Create a .env file in the root directory with your Azure OpenAI credentials:

AZURE_OPENAI_API_KEY=your-api-key
AZURE_OPENAI_BASE_URL=https://your-resource.cognitiveservices.azure.com/
AZURE_OPENAI_DEPLOYMENT=your-deployment-name

Python Usage

The Python scripts use inline dependencies (PEP 723) and run with uv run:

One-shot query

cd python
uv run ask.py "What is the capital of France?"

Interactive chat

cd python
uv run chat.py

JavaScript/Deno Usage

The JavaScript scripts can be run directly with Deno or made executable:

One-shot query

cd js
deno run --allow-env --allow-read --allow-net ask.js "What is the capital of France?"

# Or if made executable:
./ask.js "What is the capital of France?"

Interactive chat

cd js
deno run --allow-env --allow-read --allow-net chat.js

# Or if made executable:
./chat.js

Features

Both implementations provide:

  • One-shot queries: Quick questions with immediate responses
  • Interactive chat: Multi-turn conversations with context retention
  • Streaming responses: Real-time output as the AI generates text
  • Error handling: Clear error messages for configuration issues
  • No virtual environment needed: Python uses uv run, Deno runs directly

Differences

  • Python: Uses the openai package with AzureOpenAI class
  • JavaScript/Deno: Uses the same openai npm package via Deno's npm: specifier
  • Permissions: Deno requires explicit permissions (--allow-env, --allow-read, --allow-net)
  • Modern JavaScript: Uses ES modules and async/await

Troubleshooting

If you get a "DeploymentNotFound" error:

  1. Log into Azure Portal
  2. Navigate to your Azure OpenAI resource
  3. Go to "Model deployments"
  4. Copy the exact deployment name
  5. Update AZURE_OPENAI_DEPLOYMENT in your .env file

About

Simple command-line sample for Azure OpenAI in both Python and JavaScript/Deno

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published