@@ -37,6 +37,7 @@ public class OpenAiCompatibleNluProvider : INLUProvider
3737 public int Priority => 100 ;
3838
3939 private readonly HttpClient _httpClient ;
40+ private readonly IChatbotDepartmentConfigService _configService ;
4041
4142 private static readonly string IntentSystemPrompt = @"You are a classification engine for emergency service chatbot commands.
4243Classify the user's message into exactly one of these intent categories:
@@ -97,8 +98,9 @@ public class OpenAiCompatibleNluProvider : INLUProvider
9798Confidence should be between 0.0 and 1.0 based on how certain you are.
9899If the user's message doesn't clearly match any intent, set intent to ""unknown"" with confidence 0.0." ;
99100
100- public OpenAiCompatibleNluProvider ( )
101+ public OpenAiCompatibleNluProvider ( IChatbotDepartmentConfigService configService )
101102 {
103+ _configService = configService ;
102104 _httpClient = new HttpClient
103105 {
104106 Timeout = TimeSpan . FromSeconds ( ChatbotConfig . CloudNluTimeoutSeconds > 0
@@ -107,7 +109,7 @@ public OpenAiCompatibleNluProvider()
107109 } ;
108110 }
109111
110- public async Task < NLUResult > ClassifyAsync ( string text , string context = null )
112+ public async Task < NLUResult > ClassifyAsync ( string text , string context = null , int departmentId = 0 )
111113 {
112114 if ( string . IsNullOrWhiteSpace ( text ) )
113115 return new NLUResult { IntentName = "unknown" , Confidence = 0 , ProviderName = ProviderName } ;
@@ -116,9 +118,17 @@ public async Task<NLUResult> ClassifyAsync(string text, string context = null)
116118
117119 try
118120 {
119- var endpoint = ResolveEndpoint ( ) ;
120- var apiKey = ResolveApiKey ( ) ;
121- var model = ResolveModel ( ) ;
121+ // A department may supply its own LLM provider so its processing stays with that
122+ // provider; otherwise fall back to the Resgrid system-level configuration.
123+ DepartmentLlmOverride departmentLlm = null ;
124+ if ( departmentId > 0 && _configService != null )
125+ departmentLlm = await _configService . GetLlmOverrideAsync ( departmentId ) ;
126+
127+ var endpoint = departmentLlm != null ? departmentLlm . Endpoint : ResolveEndpoint ( ) ;
128+ var apiKey = departmentLlm != null ? departmentLlm . ApiKey : ResolveApiKey ( ) ;
129+ var model = departmentLlm != null && ! string . IsNullOrWhiteSpace ( departmentLlm . Model )
130+ ? departmentLlm . Model
131+ : ResolveModel ( ) ;
122132
123133 if ( string . IsNullOrWhiteSpace ( apiKey ) )
124134 {
@@ -166,8 +176,9 @@ public async Task<NLUResult> ClassifyAsync(string text, string context = null)
166176 } ;
167177 request . Headers . Add ( "Authorization" , $ "Bearer { apiKey } ") ;
168178
169- // Azure OpenAI uses api-key header instead
170- if ( ChatbotConfig . CloudNluProvider == CloudNluProviderType . AzureOpenAI )
179+ // Azure OpenAI uses api-key header instead (system config only; a department override
180+ // is assumed OpenAI-compatible with Bearer auth).
181+ if ( departmentLlm == null && ChatbotConfig . CloudNluProvider == CloudNluProviderType . AzureOpenAI )
171182 {
172183 request . Headers . Remove ( "Authorization" ) ;
173184 request . Headers . Add ( "api-key" , apiKey ) ;
0 commit comments