@@ -36,13 +36,22 @@ export class LlmService extends LoggerBase {
3636 ) {
3737 super ( parentLog )
3838
39+ if ( ! bedrockCredentials . accessKeyId || ! bedrockCredentials . secretAccessKey ) {
40+ this . log . warn ( 'LLM usage is not configured properly. Missing Bedrock credentials!' )
41+ }
42+
3943 this . qx = qx
4044 this . clientRegionMap = new Map ( )
4145 }
4246
4347 private client ( settings : ILlmSettings ) : BedrockRuntimeClient {
4448 const region = LLM_MODEL_REGION_MAP [ settings . modelId ]
4549
50+ if ( ! this . bedrockCredentials . accessKeyId || ! this . bedrockCredentials . secretAccessKey ) {
51+ this . log . warn ( 'LLM usage is not configured properly. Missing Bedrock credentials!' )
52+ return null
53+ }
54+
4655 let client : BedrockRuntimeClient
4756 if ( this . clientRegionMap . has ( region ) ) {
4857 client = this . clientRegionMap . get ( region )
@@ -67,7 +76,11 @@ export class LlmService extends LoggerBase {
6776 metadata ?: Record < string , unknown > ,
6877 saveHistory = true ,
6978 ) : Promise < ILlmResponse > {
70- if ( ! IS_LLM_ENABLED ) {
79+ if (
80+ ! IS_LLM_ENABLED ||
81+ ! this . bedrockCredentials . accessKeyId ||
82+ ! this . bedrockCredentials . secretAccessKey
83+ ) {
7184 this . log . error ( 'LLM usage is disabled. Check CROWD_LLM_ENABLED env variable!' )
7285 return
7386 }
@@ -158,6 +171,12 @@ export class LlmService extends LoggerBase {
158171 ) : Promise < ILlmResult < LlmMemberEnrichmentResult > > {
159172 const response = await this . queryLlm ( LlmQueryType . MEMBER_ENRICHMENT , prompt , memberId )
160173
174+ if ( ! response ) {
175+ return {
176+ result : null ,
177+ } as ILlmResult < LlmMemberEnrichmentResult >
178+ }
179+
161180 const result = JSON . parse ( response . answer )
162181
163182 return {
@@ -175,6 +194,12 @@ export class LlmService extends LoggerBase {
175194 memberId ,
176195 )
177196
197+ if ( ! response ) {
198+ return {
199+ result : null ,
200+ } as ILlmResult < { profileIndex : number } >
201+ }
202+
178203 const result = JSON . parse ( response . answer )
179204
180205 return {
@@ -193,6 +218,12 @@ export class LlmService extends LoggerBase {
193218 memberId ,
194219 )
195220
221+ if ( ! response ) {
222+ return {
223+ result : null ,
224+ } as ILlmResult < T >
225+ }
226+
196227 const result = JSON . parse ( response . answer )
197228
198229 return {
@@ -211,6 +242,12 @@ export class LlmService extends LoggerBase {
211242 memberId ,
212243 )
213244
245+ if ( ! response ) {
246+ return {
247+ result : null ,
248+ } as ILlmResult < T >
249+ }
250+
214251 const result = JSON . parse ( response . answer )
215252
216253 return {
@@ -225,6 +262,12 @@ export class LlmService extends LoggerBase {
225262 prompt ,
226263 )
227264
265+ if ( ! response ) {
266+ return {
267+ result : null ,
268+ } as ILlmResult < T >
269+ }
270+
228271 const result = JSON . parse ( response . answer )
229272
230273 return {
@@ -236,6 +279,12 @@ export class LlmService extends LoggerBase {
236279 public async findRepoCategories < T > ( prompt : string ) : Promise < ILlmResult < T > > {
237280 const response = await this . queryLlm ( LlmQueryType . REPO_CATEGORIES , prompt )
238281
282+ if ( ! response ) {
283+ return {
284+ result : null ,
285+ } as ILlmResult < T >
286+ }
287+
239288 const result = JSON . parse ( response . answer )
240289
241290 return {
@@ -247,6 +296,12 @@ export class LlmService extends LoggerBase {
247296 public async findRepoCollections < T > ( prompt : string ) : Promise < ILlmResult < T > > {
248297 const response = await this . queryLlm ( LlmQueryType . REPO_COLLECTIONS , prompt )
249298
299+ if ( ! response ) {
300+ return {
301+ result : null ,
302+ } as ILlmResult < T >
303+ }
304+
250305 const result = JSON . parse ( response . answer )
251306
252307 return {
0 commit comments