Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Port to OpenAI vs Azure OpenAI, port infra#34

Merged
pamelafox merged 6 commits intomainfrom
port-openai
Sep 23, 2025
Merged

Port to OpenAI vs Azure OpenAI, port infra#34
pamelafox merged 6 commits intomainfrom
port-openai

Conversation

@pamelafox
Copy link
Copy Markdown
Owner

Purpose

  • Ported from AzureOpenAI to OpenAI, as we no longer need to specify an API version, and we can pass in the token provider in the api_key parameter.
  • Enhance the README to describe every file (we were missing function calling)
  • Remove Langchain/Pydantic/Llamaindex as those are covered well in python-ai-agents-demos, so now this repo focuses on the lower-level openai package
  • Adds infrastructure-as-code for provisioning Azure OpenAI models (chat AND embedding)
  • Adds more detailed README sections about GitHub Models, Azure OpenAI, OpenAI.com, Ollama

Breakdown from Copilot:

Azure OpenAI integration and environment variable standardization:

  • Refactored all scripts to use the generic openai.OpenAI/openai.AsyncOpenAI clients for Azure, replacing AzureOpenAI/AsyncAzureOpenAI, and updated the environment variable from AZURE_OPENAI_DEPLOYMENT to AZURE_OPENAI_CHAT_DEPLOYMENT for clarity and consistency. Also updated endpoint variables to include /openai/v1 in the URL. (chained_calls.py, chat.py, chat_async.py, chat_history.py, chat_history_stream.py, .env.sample, .env.sample.azure) [1] [2] [3] [4] [5] [6] [7] [8] [9]

Async resource management improvements:

  • Improved chat_async.py to properly manage and close async clients and credentials, preventing resource leaks and ensuring clean shutdowns. [1] [2]

Documentation and onboarding enhancements:

  • Significantly expanded the README.md to provide detailed, step-by-step instructions for configuring and running scripts with GitHub Models, Azure OpenAI, OpenAI.com, and Ollama. Clarified environment variable usage and added sections for function calling, RAG, structured outputs, and infrastructure setup. [1] [2] [3] [4] [5]

Infrastructure as Code (IaC) support:

  • Added azure.yaml to define Azure Developer CLI hooks for provisioning and environment variable setup via scripts, enabling one-command resource provisioning for Azure OpenAI demos.

Code cleanup:

  • Removed the legacy Azure-specific logic and the entire chat_langchain.py script, which previously handled Azure integration differently, to streamline and unify model usage patterns.

Does this introduce a breaking change?

[ ] Yes
[X] No

Pull Request Type

What kind of change does this Pull Request introduce?

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[X] Documentation content changes
[ ] Other... Please describe:

How to Test

  • Run "azd up", run every sample.

@pamelafox pamelafox requested a review from Copilot September 22, 2025 23:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR migrates the codebase from Azure-specific OpenAI clients to the generic OpenAI client for better consistency and simplicity, while adding comprehensive infrastructure provisioning capabilities.

  • Replaces AzureOpenAI/AsyncAzureOpenAI with generic openai.OpenAI/openai.AsyncOpenAI clients across all scripts
  • Standardizes environment variable naming from AZURE_OPENAI_DEPLOYMENT to AZURE_OPENAI_CHAT_DEPLOYMENT
  • Adds Infrastructure as Code (Bicep templates) with Azure Developer CLI integration for automated resource provisioning
  • Removes higher-level framework dependencies (Langchain, LlamaIndex, PydanticAI) to focus on core OpenAI package usage
  • Enhances documentation with detailed setup instructions for all supported platforms

Reviewed Changes

Copilot reviewed 66 out of 68 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Multiple .py files Updated Azure OpenAI client initialization to use generic OpenAI client with base_url and api_key parameters
spanish/chat_async.py Enhanced async resource management with proper credential cleanup
chat_async.py Enhanced async resource management with proper credential cleanup
Infrastructure files Added Bicep templates and deployment scripts for Azure resource provisioning
README.md Significantly expanded documentation with platform-specific setup instructions
Framework files Removed Langchain, LlamaIndex, and PydanticAI example scripts

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread spanish/chat_async.py
import os

import azure.identity
import azure.identity.aio
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

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

The import has been changed from azure.identity to azure.identity.aio, but this change is inconsistent with other files in the PR that still use the synchronous azure.identity module. This could cause import errors if azure.identity.aio is not available in the installed version of the azure-identity package.

Suggested change
import azure.identity.aio
import azure.identity

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This one uses async as its the async example specifically

Comment thread chat_async.py
import os

import azure.identity
import azure.identity.aio
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

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

The import has been changed from azure.identity to azure.identity.aio, but this change is inconsistent with other files in the PR that still use the synchronous azure.identity module. This could cause import errors if azure.identity.aio is not available in the installed version of the azure-identity package.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This one uses async as its the async example specifically

Comment thread reasoning.py

response = client.chat.completions.create(
model=MODEL_NAME,
model=MODEL_NAME, # Must be a reasoning model like gpt-5 or gpt-oss
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

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

The comment mentions 'gpt-oss' which appears to be a typo. It should likely be 'o1' or another valid reasoning model name, as 'gpt-oss' is not a known OpenAI model.

Suggested change
model=MODEL_NAME, # Must be a reasoning model like gpt-5 or gpt-oss
model=MODEL_NAME, # Must be a reasoning model like gpt-5 or o1

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Lol, gpt-oss is a new open source model

@pamelafox pamelafox requested a review from madebygps September 22, 2025 23:45
Copy link
Copy Markdown
Collaborator

@madebygps madebygps left a comment

Choose a reason for hiding this comment

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

I pushed some changes, rest lgtm

@pamelafox pamelafox merged commit 43d77b1 into main Sep 23, 2025
2 checks passed
@pamelafox pamelafox deleted the port-openai branch September 23, 2025 18:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants