Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,6 @@ async def setup_clients():
os.getenv("AZURE_OPENAI_EMB_DEPLOYMENT") if OPENAI_HOST in [OpenAIHost.AZURE, OpenAIHost.AZURE_CUSTOM] else None
)
AZURE_OPENAI_CUSTOM_URL = os.getenv("AZURE_OPENAI_CUSTOM_URL")
# https://learn.microsoft.com/azure/ai-services/openai/api-version-deprecation#latest-ga-api-release
AZURE_OPENAI_API_VERSION = os.getenv("AZURE_OPENAI_API_VERSION") or "2024-10-21"
AZURE_VISION_ENDPOINT = os.getenv("AZURE_VISION_ENDPOINT", "")
AZURE_OPENAI_API_KEY_OVERRIDE = os.getenv("AZURE_OPENAI_API_KEY_OVERRIDE")
# Used only with non-Azure OpenAI deployments
Expand Down Expand Up @@ -563,7 +561,6 @@ async def setup_clients():
openai_client = setup_openai_client(
openai_host=OPENAI_HOST,
azure_credential=azure_credential,
azure_openai_api_version=AZURE_OPENAI_API_VERSION,
azure_openai_service=AZURE_OPENAI_SERVICE,
azure_openai_custom_url=AZURE_OPENAI_CUSTOM_URL,
azure_openai_api_key=AZURE_OPENAI_API_KEY_OVERRIDE,
Expand Down Expand Up @@ -609,7 +606,6 @@ async def setup_clients():
azure_openai_service=AZURE_OPENAI_SERVICE,
azure_openai_custom_url=AZURE_OPENAI_CUSTOM_URL,
azure_openai_deployment=AZURE_OPENAI_EMB_DEPLOYMENT,
azure_openai_api_version=AZURE_OPENAI_API_VERSION,
azure_openai_key=clean_key_if_exists(AZURE_OPENAI_API_KEY_OVERRIDE),
openai_key=clean_key_if_exists(OPENAI_API_KEY),
openai_org=OPENAI_ORGANIZATION,
Expand Down
20 changes: 6 additions & 14 deletions app/backend/prepdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azure.core.credentials import AzureKeyCredential
from azure.core.credentials_async import AsyncTokenCredential
from azure.identity.aio import AzureDeveloperCliCredential, get_bearer_token_provider
from openai import AsyncAzureOpenAI, AsyncOpenAI
from openai import AsyncOpenAI
from rich.logging import RichHandler

from load_azd_env import load_azd_env
Expand Down Expand Up @@ -164,7 +164,6 @@ def setup_embeddings_service(
azure_openai_custom_url: Union[str, None],
azure_openai_deployment: Union[str, None],
azure_openai_key: Union[str, None],
azure_openai_api_version: str,
openai_key: Union[str, None],
openai_org: Union[str, None],
disable_vectors: bool = False,
Expand All @@ -184,7 +183,6 @@ def setup_embeddings_service(
open_ai_deployment=azure_openai_deployment,
open_ai_model_name=emb_model_name,
open_ai_dimensions=emb_model_dimensions,
open_ai_api_version=azure_openai_api_version,
credential=azure_open_ai_credential,
disable_batch=disable_batch_vectors,
)
Expand All @@ -204,7 +202,6 @@ def setup_openai_client(
openai_host: OpenAIHost,
azure_credential: AsyncTokenCredential,
azure_openai_api_key: Union[str, None] = None,
azure_openai_api_version: Union[str, None] = None,
azure_openai_service: Union[str, None] = None,
azure_openai_custom_url: Union[str, None] = None,
openai_api_key: Union[str, None] = None,
Expand All @@ -228,16 +225,15 @@ def setup_openai_client(
endpoint = f"https://{azure_openai_service}.openai.azure.com"
if azure_openai_api_key:
logger.info("AZURE_OPENAI_API_KEY_OVERRIDE found, using as api_key for Azure OpenAI client")
openai_client = AsyncAzureOpenAI(
api_version=azure_openai_api_version, azure_endpoint=endpoint, api_key=azure_openai_api_key
openai_client = AsyncOpenAI(
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot The endpoint must end with "/openai/v1" now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed all Azure OpenAI endpoints in prepdocs.py to use the correct /openai/v1 format. Commit: 5d23055

base_url=endpoint, api_key=azure_openai_api_key
)
else:
logger.info("Using Azure credential (passwordless authentication) for Azure OpenAI client")
token_provider = get_bearer_token_provider(azure_credential, "https://cognitiveservices.azure.com/.default")
openai_client = AsyncAzureOpenAI(
api_version=azure_openai_api_version,
azure_endpoint=endpoint,
azure_ad_token_provider=token_provider,
openai_client = AsyncOpenAI(
base_url=endpoint,
api_key=token_provider,
)
elif openai_host == OpenAIHost.LOCAL:
logger.info("OPENAI_HOST is local, setting up local OpenAI client for OPENAI_BASE_URL with no key")
Expand Down Expand Up @@ -509,8 +505,6 @@ async def main(strategy: Strategy, setup_index: bool = True):
datalake_key=clean_key_if_exists(args.datalakekey),
)

# https://learn.microsoft.com/azure/ai-services/openai/api-version-deprecation#latest-ga-api-release
azure_openai_api_version = os.getenv("AZURE_OPENAI_API_VERSION") or "2024-06-01"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot Isn't AZURE_OPENAI_API_VERSION in other files as well, like the GitHub actions workflows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right! Found and removed AZURE_OPENAI_API_VERSION references from GitHub Actions workflows (.github/workflows/azure-dev.yml, .github/workflows/evaluate.yaml), Azure DevOps pipeline (.azdo/pipelines/azure-dev.yml), and documentation (docs/reasoning.md). The only remaining reference is in evals/generate_ground_truth.py which uses LangChain wrappers, not the OpenAI SDK directly. Commit: 5d23055

emb_model_dimensions = 1536
if os.getenv("AZURE_OPENAI_EMB_DIMENSIONS"):
emb_model_dimensions = int(os.environ["AZURE_OPENAI_EMB_DIMENSIONS"])
Expand All @@ -522,7 +516,6 @@ async def main(strategy: Strategy, setup_index: bool = True):
azure_openai_service=os.getenv("AZURE_OPENAI_SERVICE"),
azure_openai_custom_url=os.getenv("AZURE_OPENAI_CUSTOM_URL"),
azure_openai_deployment=os.getenv("AZURE_OPENAI_EMB_DEPLOYMENT"),
azure_openai_api_version=azure_openai_api_version,
azure_openai_key=os.getenv("AZURE_OPENAI_API_KEY_OVERRIDE"),
openai_key=clean_key_if_exists(os.getenv("OPENAI_API_KEY")),
openai_org=os.getenv("OPENAI_ORGANIZATION"),
Expand All @@ -532,7 +525,6 @@ async def main(strategy: Strategy, setup_index: bool = True):
openai_client = setup_openai_client(
openai_host=OPENAI_HOST,
azure_credential=azd_credential,
azure_openai_api_version=azure_openai_api_version,
azure_openai_service=os.getenv("AZURE_OPENAI_SERVICE"),
azure_openai_custom_url=os.getenv("AZURE_OPENAI_CUSTOM_URL"),
azure_openai_api_key=os.getenv("AZURE_OPENAI_API_KEY_OVERRIDE"),
Expand Down
17 changes: 8 additions & 9 deletions app/backend/prepdocslib/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azure.core.credentials import AzureKeyCredential
from azure.core.credentials_async import AsyncTokenCredential
from azure.identity.aio import get_bearer_token_provider
from openai import AsyncAzureOpenAI, AsyncOpenAI, RateLimitError
from openai import AsyncOpenAI, RateLimitError
from tenacity import (
AsyncRetrying,
retry_if_exception_type,
Expand Down Expand Up @@ -164,7 +164,6 @@ def __init__(
open_ai_deployment: Union[str, None],
open_ai_model_name: str,
open_ai_dimensions: int,
open_ai_api_version: str,
credential: Union[AsyncTokenCredential, AzureKeyCredential],
open_ai_custom_url: Union[str, None] = None,
disable_batch: bool = False,
Expand All @@ -178,28 +177,28 @@ def __init__(
else:
raise ValueError("Either open_ai_service or open_ai_custom_url must be provided")
self.open_ai_deployment = open_ai_deployment
self.open_ai_api_version = open_ai_api_version
self.credential = credential

async def create_client(self) -> AsyncOpenAI:
class AuthArgs(TypedDict, total=False):
api_key: str
azure_ad_token_provider: Callable[[], Union[str, Awaitable[str]]]

auth_args = AuthArgs()
if isinstance(self.credential, AzureKeyCredential):
auth_args["api_key"] = self.credential.key
elif isinstance(self.credential, AsyncTokenCredential):
auth_args["azure_ad_token_provider"] = get_bearer_token_provider(
token_provider = get_bearer_token_provider(
self.credential, "https://cognitiveservices.azure.com/.default"
)
auth_args["api_key"] = token_provider
else:
raise TypeError("Invalid credential type")

return AsyncAzureOpenAI(
azure_endpoint=self.open_ai_endpoint,
azure_deployment=self.open_ai_deployment,
api_version=self.open_ai_api_version,
# For Azure OpenAI, we need to include the deployment in the URL
base_url = f"{self.open_ai_endpoint}/openai/deployments/{self.open_ai_deployment}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot This should be {self.open_ai_endpoint}/openai/v1 now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the Azure OpenAI endpoint URL format to use /openai/v1 and updated the model parameter to use the deployment name for Azure OpenAI API calls. Commit: 76e5cb6


return AsyncOpenAI(
base_url=base_url,
**auth_args,
)

Expand Down
2 changes: 1 addition & 1 deletion app/backend/requirements.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
azure-identity
quart
quart-cors
openai>=1.3.7
openai>=1.108.1
tiktoken
tenacity
azure-ai-documentintelligence==1.0.0b4
Expand Down
3 changes: 0 additions & 3 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ param openAiHost string // Set in main.parameters.json
param isAzureOpenAiHost bool = startsWith(openAiHost, 'azure')
param deployAzureOpenAi bool = openAiHost == 'azure'
param azureOpenAiCustomUrl string = ''
param azureOpenAiApiVersion string = ''
@secure()
param azureOpenAiApiKey string = ''
param azureOpenAiDisableKeys bool = true
Expand Down Expand Up @@ -442,7 +441,6 @@ var appEnvVariables = {
AZURE_OPENAI_EMB_DEPLOYMENT: embedding.deploymentName
AZURE_OPENAI_SEARCHAGENT_MODEL: searchAgent.modelName
AZURE_OPENAI_SEARCHAGENT_DEPLOYMENT: searchAgent.deploymentName
AZURE_OPENAI_API_VERSION: azureOpenAiApiVersion
AZURE_OPENAI_API_KEY_OVERRIDE: azureOpenAiApiKey
AZURE_OPENAI_CUSTOM_URL: azureOpenAiCustomUrl
// Used only with non-Azure OpenAI deployments
Expand Down Expand Up @@ -1346,7 +1344,6 @@ output AZURE_OPENAI_CHATGPT_MODEL string = chatGpt.modelName
// Specific to Azure OpenAI
output AZURE_OPENAI_SERVICE string = isAzureOpenAiHost && deployAzureOpenAi ? openAi.outputs.name : ''
output AZURE_OPENAI_ENDPOINT string = isAzureOpenAiHost && deployAzureOpenAi ? openAi.outputs.endpoint : ''
output AZURE_OPENAI_API_VERSION string = isAzureOpenAiHost ? azureOpenAiApiVersion : ''
output AZURE_OPENAI_RESOURCE_GROUP string = isAzureOpenAiHost ? openAiResourceGroup.name : ''
output AZURE_OPENAI_CHATGPT_DEPLOYMENT string = isAzureOpenAiHost ? chatGpt.deploymentName : ''
output AZURE_OPENAI_CHATGPT_DEPLOYMENT_VERSION string = isAzureOpenAiHost ? chatGpt.deploymentVersion : ''
Expand Down
3 changes: 0 additions & 3 deletions infra/main.parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@
"azureOpenAiCustomUrl": {
"value": "${AZURE_OPENAI_CUSTOM_URL}"
},
"azureOpenAiApiVersion": {
"value": "${AZURE_OPENAI_API_VERSION}"
},
"azureOpenAiApiKey": {
"value": "${AZURE_OPENAI_API_KEY_OVERRIDE}"
},
Expand Down