Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion services/libs/common_services/src/services/llm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ export class LlmService extends LoggerBase {
) {
super(parentLog)

if (!bedrockCredentials.accessKeyId || !bedrockCredentials.secretAccessKey) {
this.log.warn('LLM usage is not configured properly. Missing Bedrock credentials!')
}

this.qx = qx
this.clientRegionMap = new Map()
}

private client(settings: ILlmSettings): BedrockRuntimeClient {
const region = LLM_MODEL_REGION_MAP[settings.modelId]

if (!this.bedrockCredentials.accessKeyId || !this.bedrockCredentials.secretAccessKey) {
this.log.warn('LLM usage is not configured properly. Missing Bedrock credentials!')
return null
}

let client: BedrockRuntimeClient
if (this.clientRegionMap.has(region)) {
client = this.clientRegionMap.get(region)
Expand All @@ -67,7 +76,11 @@ export class LlmService extends LoggerBase {
metadata?: Record<string, unknown>,
saveHistory = true,
): Promise<ILlmResponse> {
if (!IS_LLM_ENABLED) {
if (
!IS_LLM_ENABLED ||
!this.bedrockCredentials.accessKeyId ||
!this.bedrockCredentials.secretAccessKey
) {
this.log.error('LLM usage is disabled. Check CROWD_LLM_ENABLED env variable!')
return
}
Expand Down Expand Up @@ -158,6 +171,12 @@ export class LlmService extends LoggerBase {
): Promise<ILlmResult<LlmMemberEnrichmentResult>> {
const response = await this.queryLlm(LlmQueryType.MEMBER_ENRICHMENT, prompt, memberId)

if (!response) {
return {
result: null,
} as ILlmResult<LlmMemberEnrichmentResult>
}

const result = JSON.parse(response.answer)

return {
Expand All @@ -175,6 +194,12 @@ export class LlmService extends LoggerBase {
memberId,
)

if (!response) {
return {
result: null,
} as ILlmResult<{ profileIndex: number }>
}

const result = JSON.parse(response.answer)

return {
Expand All @@ -193,6 +218,12 @@ export class LlmService extends LoggerBase {
memberId,
)

if (!response) {
return {
result: null,
} as ILlmResult<T>
}

const result = JSON.parse(response.answer)

return {
Expand All @@ -211,6 +242,12 @@ export class LlmService extends LoggerBase {
memberId,
)

if (!response) {
return {
result: null,
} as ILlmResult<T>
}

const result = JSON.parse(response.answer)

return {
Expand All @@ -225,6 +262,12 @@ export class LlmService extends LoggerBase {
prompt,
)

if (!response) {
return {
result: null,
} as ILlmResult<T>
}

const result = JSON.parse(response.answer)

return {
Expand All @@ -236,6 +279,12 @@ export class LlmService extends LoggerBase {
public async findRepoCategories<T>(prompt: string): Promise<ILlmResult<T>> {
const response = await this.queryLlm(LlmQueryType.REPO_CATEGORIES, prompt)

if (!response) {
return {
result: null,
} as ILlmResult<T>
}

const result = JSON.parse(response.answer)

return {
Expand All @@ -247,6 +296,12 @@ export class LlmService extends LoggerBase {
public async findRepoCollections<T>(prompt: string): Promise<ILlmResult<T>> {
const response = await this.queryLlm(LlmQueryType.REPO_COLLECTIONS, prompt)

if (!response) {
return {
result: null,
} as ILlmResult<T>
}

const result = JSON.parse(response.answer)

return {
Expand Down
Loading