Skip to content

Commit d2f4f1d

Browse files
committed
support azure login
1 parent 21e5134 commit d2f4f1d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

optillm.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,24 @@
3131
API_KEY = os.environ.get("OPENAI_API_KEY")
3232
default_client = OpenAI(api_key=API_KEY)
3333
else:
34-
default_client = AzureOpenAI(
35-
api_key=os.environ.get("AZURE_OPENAI_API_KEY"),
36-
api_version=os.environ.get("AZURE_API_VERSION"),
37-
azure_endpoint=os.environ.get("AZURE_API_BASE"),
38-
)
34+
API_KEY = os.environ.get("AZURE_OPENAI_API_KEY")
35+
API_VERSION = os.environ.get("AZURE_API_VERSION")
36+
AZURE_ENDPOINT = os.environ.get("AZURE_API_BASE")
37+
if API_KEY is not None:
38+
default_client = AzureOpenAI(
39+
api_key=API_KEY,
40+
api_version=API_VERSION,
41+
azure_endpoint=AZURE_ENDPOINT,
42+
)
43+
else:
44+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
45+
azure_credential = DefaultAzureCredential()
46+
token_provider = get_bearer_token_provider(azure_credential, "https://cognitiveservices.azure.com/.default")
47+
default_client = AzureOpenAI(
48+
api_version=API_VERSION,
49+
azure_endpoint=AZURE_ENDPOINT,
50+
azure_ad_token_provider=token_provider
51+
)
3952

4053
# Server configuration
4154
server_config = {

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ networkx
33
openai
44
z3-solver
55
aiohttp
6-
flask
6+
flask
7+
azure.identity

0 commit comments

Comments
 (0)