@@ -63,8 +63,36 @@ def chat_api():
63
63
64
64
try :
65
65
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
68
96
gpt_client = AzureOpenAI (
69
97
api_version = settings .get ('azure_apim_gpt_api_version' ),
70
98
azure_endpoint = settings .get ('azure_apim_gpt_endpoint' ),
0 commit comments