Skip to content

Commit

Permalink
feat:job matcher service added
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadeera3784 committed Jun 16, 2024
1 parent 2308918 commit b14085a
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 28 deletions.
131 changes: 126 additions & 5 deletions apps/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"mongoose": "^8.2.0",
"morgan": "^1.10.0",
"node-mocks-http": "^1.14.1",
"openai": "^4.51.0",
"otplib": "^12.0.1",
"password-validator": "^5.3.0",
"qrcode": "^1.5.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default () => ({
model: {
gpt: 'gpt-3.5-turbo',
gpt4_0: 'gpt-4o',
}
},
},
filesystem: {
default: 's3',
Expand Down
12 changes: 12 additions & 0 deletions apps/backend/src/modules/ai/ai.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import {
OpenAIService,
OpenAIProviderService,
AIJobMatcherService,
} from './services';

@Module({
providers: [OpenAIProviderService, OpenAIService, AIJobMatcherService],
exports: [AIJobMatcherService],
})
export class AIModule {}
2 changes: 1 addition & 1 deletion apps/backend/src/modules/ai/interfaces/ai.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ export interface OutcomeMetadata extends AssociativeObject {
assessments?: AssociativeObject[];
};
comment?: string;
}
}
2 changes: 1 addition & 1 deletion apps/backend/src/modules/ai/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './ai.interface';
export * from './ai.interface';
47 changes: 47 additions & 0 deletions apps/backend/src/modules/ai/services/ai-boolean-outcome.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Injectable } from '@nestjs/common';

import { AssociativeObject, BooleanOutcome, GPTResult } from '../interfaces';
import { AIService } from './ai.service';

@Injectable()
export abstract class GPTBooleanOutcomeService extends AIService {
async handle(input: AssociativeObject): Promise<BooleanOutcome> {
const result = await this.getResult(input);

return this.getOutcomeFromResult(result);
}

protected getOutcomeFromResult(
result: GPTResult | Error | null,
): BooleanOutcome {
if (result instanceof Error) {
return {
outcome: false,
metadata: { comment: result.message },
};
}

if (!result) {
return {
outcome: false,
metadata: { comment: 'No data in response' },
};
}

const { data, notes } = result;
const comment = (data.comment as string) ?? '';

return {
metadata: { data, comment, notes },
...this.getBooleanOutcomeFromResult(result),
};
}

protected defaultOutcome(): boolean {
return false;
}

protected abstract getBooleanOutcomeFromResult(
result: GPTResult,
): Pick<BooleanOutcome, 'outcome'> & Partial<BooleanOutcome>;
}
47 changes: 47 additions & 0 deletions apps/backend/src/modules/ai/services/ai-data-outcome.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Injectable } from '@nestjs/common';

import { AssociativeObject, DataOutcome, GPTResult } from '../interfaces';
import { AIService } from './ai.service';

@Injectable()
export abstract class AIDataOutcomeService extends AIService {
async handle(input: AssociativeObject): Promise<DataOutcome> {
const result = await this.getResult(input);

return this.getOutcomeFromResult(result);
}

protected getOutcomeFromResult(
result: GPTResult | Error | null,
): DataOutcome {
if (result instanceof Error) {
return {
data: this.defaultData(),
metadata: { comment: result.message },
};
}

if (!result) {
return {
data: this.defaultData(),
metadata: { comment: 'No data in response' },
};
}

const { data, notes } = result;
const comment = (data.comment as string) ?? '';

return {
metadata: { data, comment, notes },
...this.getDataOutcomeFromResult(result),
};
}

protected defaultData(): unknown {
return null;
}

protected abstract getDataOutcomeFromResult(
result: GPTResult,
): Pick<DataOutcome, 'data'> & Partial<DataOutcome>;
}
Loading

0 comments on commit b14085a

Please sign in to comment.