Skip to content

Commit bb2ecb2

Browse files
committed
chore: update Azure OpenAI API version to 2024-12-01-preview in configurations
1 parent 368eff3 commit bb2ecb2

5 files changed

Lines changed: 29 additions & 20 deletions

File tree

ai-service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ spec:
3333
- name: AZURE_OPENAI_DALLE_ENDPOINT # required if using Azure OpenAI DALL-E
3434
value: ""
3535
- name: AZURE_OPENAI_API_VERSION # required if using Azure OpenAI DALL-E
36-
value: "2024-02-15-preview"
36+
value: "2024-12-01-preview"
3737
- name: AZURE_OPENAI_DALLE_DEPLOYMENT_NAME # required if using Azure OpenAI DALL-E
3838
value: ""
3939
- name: USE_LOCAL_LLM # set to True if you are using a local LLM provided by KAITO

charts/aks-store-demo/values.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ aiService:
2323
useAzureOpenAi: false
2424
openAiDalleEndpoint: ""
2525
openAiDalleModelName: ""
26-
azureOpenAiApiVersion: "2024-02-15-preview"
26+
azureOpenAiApiVersion: "2024-12-01-preview"
2727
image:
2828
repository: "ghcr.io/azure-samples/aks-store-demo/ai-service"
2929
tag: "" # defaults to Chart.AppVersion
@@ -90,12 +90,10 @@ virtualWorker:
9090

9191
podAnnotations: {}
9292

93-
podSecurityContext:
94-
{}
93+
podSecurityContext: {}
9594
# fsGroup: 2000
9695

97-
securityContext:
98-
{}
96+
securityContext: {}
9997
# capabilities:
10098
# drop:
10199
# - ALL

src/ai-service/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pip3 install -r requirements.txt
2424

2525
export USE_AZURE_OPENAI=True # set to False if you are not using Azure OpenAI
2626
export USE_AZURE_AD=True # set to True if you are using Azure OpenAI with Azure AD authentication
27-
export AZURE_OPENAI_API_VERSION=2024-02-15-preview # set to the version of the Azure OpenAI API you are using https://learn.microsoft.com/azure/ai-services/openai/reference#rest-api-versioning
27+
export AZURE_OPENAI_API_VERSION=2024-12-01-preview # set to the version of the Azure OpenAI API you are using https://learn.microsoft.com/azure/ai-services/openai/reference#rest-api-versioning
2828
export AZURE_OPENAI_DEPLOYMENT_NAME= # required if using Azure OpenAI
2929
export AZURE_OPENAI_ENDPOINT= # required if using Azure OpenAI
3030
export AZURE_OPENAI_DALLE_ENDPOINT= # required if using Azure OpenAI's DALL-E model

src/ai-service/routers/description_generator.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Description generation API endpoint.
33
"""
4+
45
import os
56
import logging
67
from typing import List
@@ -25,16 +26,17 @@
2526
"with the following tags: '{tags}'."
2627
)
2728

29+
2830
class DescriptionRequest(BaseModel):
2931
"""Request model for the description generation endpoint."""
32+
3033
name: str
3134
tags: List[str]
3235

36+
3337
# Create router with prefix
34-
description = APIRouter(
35-
prefix="/generate",
36-
tags=["generation"]
37-
)
38+
description = APIRouter(prefix="/generate", tags=["generation"])
39+
3840

3941
def _create_completion(client, model, prompt, system_prompt=SYSTEM_PROMPT):
4042
"""Create a chat completion using the provided client and model"""
@@ -47,6 +49,7 @@ def _create_completion(client, model, prompt, system_prompt=SYSTEM_PROMPT):
4749
temperature=0,
4850
)
4951

52+
5053
def _handle_local_llm(user_prompt):
5154
"""Handle local LLM completion"""
5255
logger.info("Using local LLM")
@@ -66,6 +69,7 @@ def _handle_local_llm(user_prompt):
6669
response = _create_completion(client, model, user_prompt)
6770
return response.choices[0].message.content
6871

72+
6973
def _handle_openai(user_prompt):
7074
"""Handle OpenAI completion"""
7175
api_key = os.environ.get("OPENAI_API_KEY")
@@ -83,6 +87,7 @@ def _handle_openai(user_prompt):
8387
response = _create_completion(client, "gpt-3.5-turbo", user_prompt)
8488
return response.choices[0].message.content
8589

90+
8691
def _handle_azure_openai(user_prompt, use_azure_ad):
8792
"""Handle Azure OpenAI completion"""
8893
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME")
@@ -95,13 +100,12 @@ def _handle_azure_openai(user_prompt, use_azure_ad):
95100
"AZURE_OPENAI_DEPLOYMENT_NAME and AZURE_OPENAI_ENDPOINT must be provided"
96101
)
97102

98-
api_version = os.environ.get("AZURE_OPENAI_API_VERSION", "2024-02-15-preview")
103+
api_version = os.environ.get("AZURE_OPENAI_API_VERSION", "2024-12-01-preview")
99104

100105
if use_azure_ad:
101106
logger.info("Using Microsoft Entra authentication")
102107
token_provider = get_bearer_token_provider(
103-
DefaultAzureCredential(),
104-
"https://cognitiveservices.azure.com/.default"
108+
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
105109
)
106110

107111
client = AzureOpenAI(
@@ -125,6 +129,7 @@ def _handle_azure_openai(user_prompt, use_azure_ad):
125129
response = _create_completion(client, deployment, user_prompt)
126130
return response.choices[0].message.content
127131

132+
128133
@description.post("/description", operation_id="generate_description")
129134
async def generate_description(request: DescriptionRequest):
130135
"""
@@ -133,8 +138,7 @@ async def generate_description(request: DescriptionRequest):
133138
try:
134139
# Format the user prompt with the product name and tags
135140
user_prompt = USER_PROMPT_TEMPLATE.format(
136-
name=request.name,
137-
tags=", ".join(request.tags)
141+
name=request.name, tags=", ".join(request.tags)
138142
)
139143

140144
env_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env")
@@ -156,6 +160,5 @@ async def generate_description(request: DescriptionRequest):
156160
return {"description": description_text}
157161
except Exception as e:
158162
raise HTTPException(
159-
status_code=500,
160-
detail=f"Error generating description: {str(e)}"
163+
status_code=500, detail=f"Error generating description: {str(e)}"
161164
) from e

src/product-service/docker-compose.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ services:
77
ports:
88
- 5001:5001
99
healthcheck:
10-
test: ["CMD", "wget", "-O", "/dev/null", "-q", "http://ai-service:5001/health"]
10+
test:
11+
[
12+
"CMD",
13+
"wget",
14+
"-O",
15+
"/dev/null",
16+
"-q",
17+
"http://ai-service:5001/health",
18+
]
1119
interval: 30s
1220
timeout: 10s
1321
retries: 5
@@ -17,7 +25,7 @@ services:
1725
- AZURE_OPENAI_ENDPOINT= # required if using Azure OpenAI
1826
- OPENAI_API_KEY= # always required
1927
- AZURE_OPENAI_DALLE_ENDPOINT= # required if using Azure OpenAI DALL-E
20-
- AZURE_OPENAI_API_VERSION=2024-02-15-preview # required if using Azure OpenAI
28+
- AZURE_OPENAI_API_VERSION=2024-12-01-preview # required if using Azure OpenAI
2129
- AZURE_OPENAI_DALLE_DEPLOYMENT_NAME= # required if using Azure OpenAI DALL-E
2230
networks:
2331
- backend_services

0 commit comments

Comments
 (0)