Skip to content

Commit 1100eae

Browse files
authored
uses APIM with multiple models (#207)
1 parent 3a68c81 commit 1100eae

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

application/single_app/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
app.config['SECRET_KEY'] = os.getenv("SECRET_KEY")
8888
app.config['SESSION_TYPE'] = 'filesystem'
89-
app.config['VERSION'] = '0.213.002'
89+
app.config['VERSION'] = '0.213.003'
9090
Session(app)
9191

9292
CLIENTS = {}

application/single_app/route_backend_chats.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,36 @@ def chat_api():
6363

6464
try:
6565
if enable_gpt_apim:
66-
gpt_model = settings.get('azure_apim_gpt_deployment')
67-
if not gpt_model: raise ValueError("APIM GPT deployment name not configured.")
66+
# read raw comma-delimited deployments
67+
raw = settings.get('azure_apim_gpt_deployment', '')
68+
if not raw:
69+
raise ValueError("APIM GPT deployment name not configured.")
70+
71+
# split, strip, and filter out empty entries
72+
apim_models = [m.strip() for m in raw.split(',') if m.strip()]
73+
if not apim_models:
74+
raise ValueError("No valid APIM GPT deployment names found.")
75+
76+
# if frontend specified one, use it (must be in the configured list)
77+
if frontend_gpt_model:
78+
if frontend_gpt_model not in apim_models:
79+
raise ValueError(
80+
f"Requested model '{frontend_gpt_model}' is not configured for APIM."
81+
)
82+
gpt_model = frontend_gpt_model
83+
84+
# otherwise if there's exactly one deployment, default to it
85+
elif len(apim_models) == 1:
86+
gpt_model = apim_models[0]
87+
88+
# otherwise you must pass model_deployment in the request
89+
else:
90+
raise ValueError(
91+
"Multiple APIM GPT deployments configured; please include "
92+
"'model_deployment' in your request."
93+
)
94+
95+
# initialize the APIM client
6896
gpt_client = AzureOpenAI(
6997
api_version=settings.get('azure_apim_gpt_api_version'),
7098
azure_endpoint=settings.get('azure_apim_gpt_endpoint'),

0 commit comments

Comments
 (0)