Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluator status #26

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/controllers/evaluationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const evaluateApplication = async (
alloApplicationId,
cid,
evaluator,
evaluationStatus,
summaryInput,
chainId,
signature,
Expand All @@ -126,6 +127,7 @@ export const evaluateApplication = async (
alloApplicationId,
cid,
evaluator,
evaluationStatus,
summaryInput,
};

Expand Down
11 changes: 11 additions & 0 deletions src/entity/Evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export enum EVALUATOR_TYPE {
LLM_GPT3 = 'llm_gpt3', // evaluator: address(1)
}

export enum EVALUATION_STATUS {
APPROVED = 'approved',
REJECTED = 'rejected',
}

@Entity()
@Unique(['evaluator', 'applicationId'])
export class Evaluation {
Expand All @@ -37,6 +42,12 @@ export class Evaluation {
@Column()
evaluatorScore: number;

@Column({
type: 'enum',
enum: EVALUATION_STATUS,
})
evaluationStatus: EVALUATION_STATUS;

@Column()
metadataCid: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { type MigrationInterface, type QueryRunner } from "typeorm";

export class InitMigration1732016597076 implements MigrationInterface {
name = 'InitMigration1732016597076'
export class InitMigration1732106699497 implements MigrationInterface {
name = 'InitMigration1732106699497'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "evaluation" ("id" SERIAL NOT NULL, "evaluator" character varying(42) NOT NULL, "evaluatorType" "public"."evaluation_evaluatortype_enum" NOT NULL, "summary" character varying NOT NULL, "evaluatorScore" integer NOT NULL, "metadataCid" character varying NOT NULL, "applicationId" integer NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "lastUpdatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_566857ce7db15aa0fb1930b4cdf" UNIQUE ("evaluator", "applicationId"), CONSTRAINT "PK_b72edd439b9db736f55b584fa54" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TYPE "public"."evaluation_evaluationstatus_enum" AS ENUM('approved', 'rejected')`);
await queryRunner.query(`CREATE TABLE "evaluation" ("id" SERIAL NOT NULL, "evaluator" character varying(42) NOT NULL, "evaluatorType" "public"."evaluation_evaluatortype_enum" NOT NULL, "summary" character varying NOT NULL, "evaluatorScore" integer NOT NULL, "evaluationStatus" "public"."evaluation_evaluationstatus_enum" NOT NULL, "metadataCid" character varying NOT NULL, "applicationId" integer NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "lastUpdatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UQ_566857ce7db15aa0fb1930b4cdf" UNIQUE ("evaluator", "applicationId"), CONSTRAINT "PK_b72edd439b9db736f55b584fa54" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "evaluation_answer" ("id" SERIAL NOT NULL, "answer" "public"."evaluation_answer_answer_enum" NOT NULL, "evaluationId" integer NOT NULL, "evaluationQuestionId" integer NOT NULL, CONSTRAINT "UQ_5d5571491f885c88023b5f56366" UNIQUE ("evaluationId", "evaluationQuestionId"), CONSTRAINT "PK_26adcf2e8e65214d2558b8f6910" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "evaluation_question" ("id" SERIAL NOT NULL, "questionIndex" integer NOT NULL, "question" character varying NOT NULL, "poolId" integer NOT NULL, CONSTRAINT "UQ_bd9653bd57844a98c0863a0a5b8" UNIQUE ("poolId", "questionIndex"), CONSTRAINT "PK_6ecc0e6614b9c4bc65c6de2c021" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "pool" ("id" SERIAL NOT NULL, "chainId" integer NOT NULL, "alloPoolId" character varying NOT NULL, CONSTRAINT "UQ_72fcaa655b2b7348f4feaf25ea3" UNIQUE ("chainId", "alloPoolId"), CONSTRAINT "PK_db1bfe411e1516c01120b85f8fe" PRIMARY KEY ("id"))`);
Expand All @@ -31,6 +32,7 @@ export class InitMigration1732016597076 implements MigrationInterface {
await queryRunner.query(`DROP TABLE "evaluation_question"`);
await queryRunner.query(`DROP TABLE "evaluation_answer"`);
await queryRunner.query(`DROP TABLE "evaluation"`);
await queryRunner.query(`DROP TYPE "public"."evaluation_evaluationstatus_enum"`);
}

}
1 change: 1 addition & 0 deletions src/routes/evaluationRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const router = Router();
* alloPoolId: "609"
* alloApplicationId: "0"
* evaluator: "0x12345abcdef67890"
* evaluationStatus: "approved"
* cid: "cid1234567890"
* summaryInput:
* questions:
Expand Down
17 changes: 16 additions & 1 deletion src/service/EvaluationService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { type Evaluation, EVALUATOR_TYPE } from '@/entity/Evaluation';
import {
type Evaluation,
EVALUATION_STATUS,
EVALUATOR_TYPE,
} from '@/entity/Evaluation';
import {
evaluationQuestionRepository,
evaluationRepository,
Expand Down Expand Up @@ -27,6 +31,7 @@ export interface CreateEvaluationParams {
cid: string;
evaluator: string;
summaryInput: EvaluationSummaryInput;
evaluationStatus?: EVALUATION_STATUS;
evaluatorType?: EVALUATOR_TYPE;
}

Expand Down Expand Up @@ -70,6 +75,7 @@ class EvaluationService {
cid,
evaluator,
summaryInput,
evaluationStatus = EVALUATION_STATUS.REJECTED,
evaluatorType = EVALUATOR_TYPE.HUMAN,
}: CreateEvaluationParams): Promise<Evaluation> {
const { questions, summary } = summaryInput;
Expand Down Expand Up @@ -97,12 +103,21 @@ class EvaluationService {
(1 - totalScore / maxPossibleScore) * 100
);

// Set the evaluation status if the evaluator is not human
if (evaluatorType !== EVALUATOR_TYPE.HUMAN) {
evaluationStatus =
evaluatorScore >= 60
? EVALUATION_STATUS.APPROVED
: EVALUATION_STATUS.REJECTED;
}

// Create the Evaluation
const evaluation = await this.createEvaluation({
evaluator,
evaluatorType,
summary,
evaluatorScore,
evaluationStatus,
metadataCid: cid,
applicationId: application.id,
application,
Expand Down