-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Woody Rousseau
committed
Mar 10, 2024
1 parent
5abaa17
commit 01102e9
Showing
13 changed files
with
136 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Type, UsePipes } from '@nestjs/common'; | ||
import { AICheckPipe } from '../pipes'; | ||
|
||
export function AIFeedback(dtoType: Type<any>): MethodDecorator { | ||
return function (target: any, key: any, descriptor: PropertyDescriptor) { | ||
UsePipes(AICheckPipe(dtoType))(target, key, descriptor); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './generative-ai-check.decorator'; | ||
export * from './generative-ai-specifications.decorator'; | ||
export * from './generative-ai-feedback.decorator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,54 @@ | ||
import { Injectable, PipeTransform, Type } from '@nestjs/common'; | ||
import { Inject, PipeTransform, Type, mixin } from '@nestjs/common'; | ||
import { FeedbackEnriched } from '../interfaces/generative-ai.interface'; | ||
import { AIFeedbackEngine } from '../generative-ai.service'; | ||
import { FieldsSpecificationsStore } from '../utils'; | ||
|
||
@Injectable() | ||
export class AICheckPipe<T> | ||
implements PipeTransform<T, Promise<FeedbackEnriched<T>>> | ||
{ | ||
constructor( | ||
private expectedType: Type<any>, | ||
private readonly feedbackEngine: AIFeedbackEngine, | ||
) {} | ||
async transform(value: T): Promise<FeedbackEnriched<T>> { | ||
const fieldsSpecifications = | ||
FieldsSpecificationsStore.getClassFieldsSpecifications( | ||
this.expectedType.name, | ||
); | ||
|
||
if (fieldsSpecifications !== undefined) { | ||
const input = value[fieldsSpecifications.fieldName]; | ||
const specifications = fieldsSpecifications.specifications; | ||
|
||
const feedback = | ||
await this.feedbackEngine.generateFeedbackOnInputWithGuidelines( | ||
input, | ||
specifications, | ||
import { AIService } from '../generative-ai.service'; | ||
import { FieldsSpecificationsStore, memoize } from '../utils'; | ||
|
||
export type IAICheckPipe = { | ||
transform<T>(value: T): Promise<FeedbackEnriched<T>>; | ||
}; | ||
|
||
export const AICheckPipe: (expectedType: Type<any>) => Type<IAICheckPipe> = | ||
memoize(createAICheckPipe); | ||
|
||
function createAICheckPipe(expectedType: Type<any>): Type<IAICheckPipe> { | ||
class MixinAICheckPipe<T> | ||
implements PipeTransform<T, Promise<FeedbackEnriched<T>>> | ||
{ | ||
protected aiService: AIService; | ||
constructor(@Inject(AIService) feedbackEngine: AIService) { | ||
this.aiService = feedbackEngine; | ||
} | ||
|
||
async transform(value: T): Promise<FeedbackEnriched<T>> { | ||
const fieldsSpecifications = | ||
FieldsSpecificationsStore.getClassFieldsSpecifications( | ||
expectedType.name, | ||
); | ||
|
||
if (fieldsSpecifications !== undefined) { | ||
const input = value[fieldsSpecifications.fieldName]; | ||
const specifications = fieldsSpecifications.specifications; | ||
|
||
const feedback = | ||
await this.aiService.generateFeedbackOnInputWithGuidelines( | ||
input, | ||
specifications, | ||
); | ||
|
||
return { | ||
data: value, | ||
feedback, | ||
}; | ||
} | ||
|
||
return { | ||
data: value, | ||
feedback, | ||
feedback: undefined, | ||
}; | ||
} | ||
|
||
return { | ||
data: value, | ||
feedback: undefined, | ||
}; | ||
} | ||
|
||
const pipe = mixin(MixinAICheckPipe); | ||
|
||
return pipe as Type<IAICheckPipe>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './memoize'; | ||
export * from './stores'; |
Oops, something went wrong.