Skip to content

Commit f6ea6d5

Browse files
changes v1
1 parent 160439d commit f6ea6d5

5 files changed

Lines changed: 31 additions & 14 deletions

File tree

src/ContentProcessor/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ azure-appconfiguration>=1.7.1
22
azure-identity>=1.19.0
33
azure-storage-blob>=12.24.1
44
azure-storage-queue>=12.12.0
5+
azure-ai-projects>=1.0.0b5
56
certifi>=2024.12.14
67
charset-normalizer>=3.4.1
7-
openai==2.0.0
88
pandas>=2.2.3
99
pdf2image>=1.17.0
1010
poppler-utils>=0.1.0

src/ContentProcessor/src/libs/application/application_configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AppConfiguration(ModelBaseSettings):
2525
app_cps_processes (str): Folder name CPS processes name in Blob Container.
2626
app_cps_configuration (str): Folder CPS configuration name Blob Container.
2727
app_content_understanding_endpoint (str): The endpoint for content understanding Service.
28+
app_ai_project_endpoint (str): The AI Foundry project endpoint.
2829
app_azure_openai_endpoint (str): The endpoint for Azure OpenAI.
2930
app_azure_openai_model (str): The model for Azure OpenAI.
3031
app_cosmos_connstr (str): The connection string for Cosmos DB.
@@ -44,6 +45,7 @@ class AppConfiguration(ModelBaseSettings):
4445
app_cps_processes: str
4546
app_cps_configuration: str
4647
app_content_understanding_endpoint: str
48+
app_ai_project_endpoint: str
4749
app_azure_openai_endpoint: str
4850
app_azure_openai_model: str
4951
app_cosmos_connstr: str
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4-
from azure.identity import get_bearer_token_provider
4+
from azure.ai.projects import AIProjectClient
55
from helpers.azure_credential_utils import get_azure_credential
6-
from openai import AzureOpenAI
76

87

9-
def get_openai_client(azure_openai_endpoint: str) -> AzureOpenAI:
8+
def get_foundry_client(ai_project_endpoint: str):
9+
"""
10+
Create an OpenAI-compatible client via Azure AI Foundry (Projects SDK).
11+
12+
This function uses the Azure AI Foundry approach:
13+
1. Create an AIProjectClient with the AI project endpoint
14+
2. Call .get_openai_client() to get an OpenAI-compatible client
15+
16+
Args:
17+
ai_project_endpoint: The AI Foundry project endpoint URL (e.g., https://aif-xyz.services.ai.azure.com)
18+
19+
Returns:
20+
An OpenAI-compatible client from the AI Foundry project
21+
"""
1022
credential = get_azure_credential()
11-
token_provider = get_bearer_token_provider(
12-
credential, "https://cognitiveservices.azure.com/.default"
13-
)
14-
return AzureOpenAI(
15-
azure_endpoint=azure_openai_endpoint,
16-
azure_ad_token_provider=token_provider,
17-
api_version="2024-10-01-preview",
23+
24+
# Create the AI Foundry Project client
25+
project_client = AIProjectClient(
26+
endpoint=ai_project_endpoint,
27+
credential=credential
1828
)
29+
30+
# Get the OpenAI-compatible client from the project
31+
# This client supports .beta.chat.completions.parse() and other OpenAI methods
32+
return project_client.get_openai_client()

src/ContentProcessor/src/libs/pipeline/handlers/map_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pdf2image import convert_from_bytes
99

1010
from libs.application.application_context import AppContext
11-
from libs.azure_helper.azure_openai import get_openai_client
11+
from libs.azure_helper.azure_openai import get_foundry_client
1212
from libs.azure_helper.model.content_understanding import AnalyzedResult
1313
from libs.pipeline.entities.mime_types import MimeTypes
1414
from libs.pipeline.entities.pipeline_file import ArtifactType, PipelineLogEntry
@@ -82,8 +82,8 @@ async def execute(self, context: MessageContext) -> StepResult:
8282
)
8383

8484
# Invoke GPT with the prompt
85-
gpt_response = get_openai_client(
86-
self.application_context.configuration.app_azure_openai_endpoint
85+
gpt_response = get_foundry_client(
86+
self.application_context.configuration.app_ai_project_endpoint
8787
).beta.chat.completions.parse(
8888
model=self.application_context.configuration.app_azure_openai_model,
8989
messages=[

src/ContentProcessor/src/tests/test_main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ async def test_application_run(mocker):
5555
ConfigItem(
5656
"app_content_understanding_endpoint", "https://example.com/content"
5757
),
58+
ConfigItem("app_ai_project_endpoint", "https://example.ai.azure.com"),
5859
ConfigItem("app_azure_openai_endpoint", "https://example.com/openai"),
5960
ConfigItem("app_azure_openai_model", "model-name"),
6061
ConfigItem(

0 commit comments

Comments
 (0)