Skip to content

fix: add AzureOpenAI class to guidance.models#1448

Open
octo-patch wants to merge 1 commit into
guidance-ai:mainfrom
octo-patch:fix/issue-1205-add-azureopenai-class
Open

fix: add AzureOpenAI class to guidance.models#1448
octo-patch wants to merge 1 commit into
guidance-ai:mainfrom
octo-patch:fix/issue-1205-add-azureopenai-class

Conversation

@octo-patch

Copy link
Copy Markdown

Fixes #1205

Problem

guidance.models.AzureOpenAI does not exist as a public API, causing an AttributeError when users try to use it as documented in the AzureOpenAI example notebook. Users familiar with the guidance.models.OpenAI class pattern expect a similar AzureOpenAI class.

Solution

Add an AzureOpenAI class to guidance/models/_azureai.py that follows the same pattern as the existing OpenAI class:

  • Takes model as the first positional argument (consistent with OpenAI)
  • Requires azure_endpoint and azure_deployment arguments
  • Supports api_version, api_key, azure_ad_token, azure_ad_token_provider, and other keyword arguments
  • Automatically selects the appropriate interpreter based on model name (audio/image support detection mirrors create_azure_openai_model)
  • Exports AzureOpenAI from guidance.models.__init__

The existing create_azure_openai_model factory function is preserved unchanged for backward compatibility.

Usage after this fix

from guidance import models

azureai_model = models.AzureOpenAI(
    model="gpt-4o-mini",
    azure_endpoint="https://my-resource.openai.azure.com/",
    azure_deployment="my-deployment",
    api_version="2024-02-15-preview",
    azure_ad_token_provider=token_provider,
)

Testing

Verified that:

  • AzureOpenAI class is importable from guidance.models
  • Syntax is correct (AST parse passes)
  • Existing create_azure_openai_model tests remain unaffected
  • The new class delegates to the same AzureOpenAIInterpreter classes as the factory function

Add an AzureOpenAI class that mirrors the OpenAI class interface,
allowing users to use guidance.models.AzureOpenAI(model=...,
azure_endpoint=..., azure_deployment=...) instead of the
create_azure_openai_model factory function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

models.AzureOpenAI class missing in guidance.models despite example notebook

1 participant