Skip to content

Commit a5fbe8b

Browse files
authored
chore: add LLM usage toggle based on env variable (#3385)
1 parent da50bad commit a5fbe8b

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

backend/src/services/collectionService.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,7 @@ export class CollectionService extends LoggerBase {
449449
const repositoryGroupIds: string[] = rg.map((rg) => rg.id) as string[]
450450

451451
// Find repository groups that need to be updated (exist in both lists)
452-
const toUpdate: ICreateRepositoryGroup[] = rg.filter((rg) =>
453-
existingIds.includes(rg.id),
454-
)
452+
const toUpdate: ICreateRepositoryGroup[] = rg.filter((rg) => existingIds.includes(rg.id))
455453

456454
// Find repository groups that need to be created (don't exist or have no ID)
457455
const toCreate: ICreateRepositoryGroup[] = rg.filter(

services/apps/merge_suggestions_worker/src/activities/common.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BedrockRuntimeClient, InvokeModelCommand } from '@aws-sdk/client-bedroc
33
import axios from 'axios'
44
import { performance } from 'perf_hooks'
55

6+
import { IS_LLM_ENABLED } from '@crowd/common'
67
import { ITenant } from '@crowd/data-access-layer/src/old/apps/merge_suggestions_worker//types'
78
import LLMSuggestionVerdictsRepository from '@crowd/data-access-layer/src/old/apps/merge_suggestions_worker/llmSuggestionVerdicts.repo'
89
import TenantRepository from '@crowd/data-access-layer/src/old/apps/merge_suggestions_worker/tenant.repo'
@@ -37,10 +38,16 @@ export async function getLLMResult(
3738
region: string,
3839
modelSpecificArgs: any,
3940
): Promise<ILLMResult> {
41+
if (!IS_LLM_ENABLED) {
42+
svc.log.error('LLM usage is disabled. Check CROWD_LLM_ENABLED env variable!')
43+
return
44+
}
45+
4046
if (suggestion.length !== 2) {
4147
console.log(suggestion)
4248
throw new Error('Exactly 2 entities are required for LLM comparison')
4349
}
50+
4451
const client = new BedrockRuntimeClient({
4552
credentials: {
4653
accessKeyId: process.env['CROWD_AWS_BEDROCK_ACCESS_KEY_ID'],

services/libs/common/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const LOG_LEVEL: string = process.env.LOG_LEVEL || 'info'
1515

1616
export const IS_CLOUD_ENV: boolean = IS_PROD_ENV || IS_STAGING_ENV
1717

18+
export const IS_LLM_ENABLED: boolean = process.env.CROWD_ENABLE_LLM === 'true' || false
19+
1820
export const SERVICE = process.env.SERVICE || 'unknown-service'
1921

2022
export const EDITION: Edition = process.env.CROWD_EDITION as Edition

services/libs/common_services/src/services/llm.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@aws-sdk/client-bedrock-runtime'
66
import { performance } from 'perf_hooks'
77

8+
import { IS_LLM_ENABLED } from '@crowd/common'
89
import { insertPromptHistoryEntry } from '@crowd/data-access-layer'
910
import { QueryExecutor } from '@crowd/data-access-layer'
1011
import { Logger, LoggerBase } from '@crowd/logging'
@@ -66,6 +67,11 @@ export class LlmService extends LoggerBase {
6667
metadata?: Record<string, unknown>,
6768
saveHistory = true,
6869
): Promise<ILlmResponse> {
70+
if (!IS_LLM_ENABLED) {
71+
this.log.error('LLM usage is disabled. Check CROWD_LLM_ENABLED env variable!')
72+
return
73+
}
74+
6975
const settings = LLM_SETTINGS[type]
7076
if (!settings) {
7177
throw new Error(`No settings found for LLM query type: ${type}`)

0 commit comments

Comments
 (0)