Skip to content

Commit a3e3e33

Browse files
committed
Switches AI backend integration from OpenAI to Azure API
1 parent 4347a5b commit a3e3e33

5 files changed

Lines changed: 29 additions & 17 deletions

File tree

.example.env

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ AUTH_PORT=8081
2121

2222
# AI Service
2323
AI_SERVICE_PORT=5000
24-
OPENAI_API_KEY = "<key>"
25-
AI_MODEL=gpt-4o-mini
24+
AZURE_ENDPOINT=https://your-azure-endpoint.openai.azure.com/
25+
AZURE_DEPLOYMENT_NAME=your-deployment-name
26+
AZURE_API_VERSION=2024-06-01-preview
27+
AZURE_API_KEY=your-azure-api-key

AI/app/services/llm_service.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
from langchain_openai import AzureOpenAI
1+
from langchain_openai import AzureChatOpenAI
22
from langchain.chat_models.base import BaseChatModel
33
from app.settings import settings
44

55
class LLMService:
66
model: BaseChatModel
77

88
def __init__(self):
9-
self.model = AzureOpenAI(
9+
self.model = AzureChatOpenAI(
1010
temperature=0.7,
11-
model_name="gpt-5-mini",
12-
api_key=settings.OPENAI_API_KEY
11+
api_key=settings.AZURE_API_KEY,
12+
azure_endpoint=settings.AZURE_ENDPOINT,
13+
azure_deployment=settings.AZURE_DEPLOYMENT_NAME,
14+
api_version=settings.AZURE_API_VERSION,
1315
)
1416

1517
async def generate_content(self, prompt: str) -> str:
1618
response = await self.model.ainvoke(prompt)
1719
return response.content
1820

19-
llm_service = LLMService()
21+
llm_service = LLMService()

AI/app/settings.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from pydantic_settings import BaseSettings
1+
from pydantic_settings import BaseSettings, SettingsConfigDict
2+
23

34
class Settings(BaseSettings):
4-
OPENAI_API_KEY: str = ""
5-
6-
class Config:
7-
env_file = ".env"
5+
AZURE_API_KEY: str = ""
6+
AZURE_ENDPOINT: str = ""
7+
AZURE_DEPLOYMENT_NAME: str = ""
8+
AZURE_API_VERSION: str = ""
9+
10+
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
11+
812

9-
settings = Settings()
13+
settings = Settings()

docker/docker-compose.dev.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ services:
2222
volumes:
2323
- overlap_data:/code/data
2424
environment:
25-
OPENAI_API_KEY: ${OPENAI_API_KEY}
26-
AI_MODEL: ${AI_MODEL}
25+
AZURE_API_KEY: ${AZURE_API_KEY}
26+
AZURE_ENDPOINT: ${AZURE_ENDPOINT}
27+
AZURE_DEPLOYMENT_NAME: ${AZURE_DEPLOYMENT_NAME}
28+
AZURE_API_VERSION: ${AZURE_API_VERSION}
2729
ports:
2830
- "${AI_SERVICE_PORT}:5000"
2931
networks:

docker/docker-compose.prod.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ services:
3737
volumes:
3838
- overlap_data:/code/data
3939
environment:
40-
OPENAI_API_KEY: ${OPENAI_API_KEY}
41-
AI_MODEL: ${AI_MODEL}
40+
AZURE_API_KEY: ${AZURE_API_KEY}
41+
AZURE_ENDPOINT: ${AZURE_ENDPOINT}
42+
AZURE_DEPLOYMENT_NAME: ${AZURE_DEPLOYMENT_NAME}
43+
AZURE_API_VERSION: ${AZURE_API_VERSION}
4244
ports:
4345
- "${AI_SERVICE_PORT}:5000"
4446
networks:

0 commit comments

Comments
 (0)