From 71a5c1ad024203526a1c52b8e8369d0d008093f6 Mon Sep 17 00:00:00 2001 From: ishowvel Date: Tue, 29 Oct 2024 06:22:24 +0000 Subject: [PATCH] feat: multiply conv reward with priority for higher reward --- src/helpers/label-price-extractor.ts | 42 ++++++++++++++++++++++++++ src/parser/content-evaluator-module.ts | 15 +++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/helpers/label-price-extractor.ts b/src/helpers/label-price-extractor.ts index 28c1ee65..11f13c65 100644 --- a/src/helpers/label-price-extractor.ts +++ b/src/helpers/label-price-extractor.ts @@ -20,3 +20,45 @@ export function getSortedPrices(labels: GitHubIssue["labels"] | undefined) { } return sortedPriceLabels; } + +export function parsePriorityLabel( + labels: ( + | string + | { + id?: number; + node_id?: string; + url?: string; + name?: string; + description?: string | null; + color?: string | null; + default?: boolean; + } + )[] +): number { + let taskPriorityEstimate = 0; + + for (const label of labels) { + let priorityLabel = ""; + if (typeof label === "string") { + priorityLabel = label; + } else { + priorityLabel = label.name ?? ""; + } + + if (priorityLabel.startsWith("Priority:")) { + const matched = priorityLabel.match(/Priority: (\d+)/i); + if (!matched) { + return 0; + } + + const urgency = matched[1]; + taskPriorityEstimate = Number(urgency); + } + + if (taskPriorityEstimate) { + break; + } + } + + return taskPriorityEstimate; +} diff --git a/src/parser/content-evaluator-module.ts b/src/parser/content-evaluator-module.ts index 877d5c32..f1fb9555 100644 --- a/src/parser/content-evaluator-module.ts +++ b/src/parser/content-evaluator-module.ts @@ -19,6 +19,7 @@ import { Relevances, } from "../types/content-evaluator-module-type"; import { GithubCommentScore, Module, Result } from "./processor"; +import { parsePriorityLabel } from "../helpers/label-price-extractor"; /** * Evaluates and rates comments. @@ -73,9 +74,12 @@ export class ContentEvaluatorModule implements Module { const currentElement = result[key]; const comments = currentElement.comments ?? []; const specificationBody = data.self?.body; + const issueLabels = data.self?.labels; + const priority = issueLabels ? parsePriorityLabel(issueLabels) : undefined; + if (specificationBody && comments.length) { promises.push( - this._processComment(comments, specificationBody, allComments).then( + this._processComment(comments, priority, specificationBody, allComments).then( (commentsWithScore) => (currentElement.comments = commentsWithScore) ) ); @@ -99,7 +103,12 @@ export class ContentEvaluatorModule implements Module { return reward; } - async _processComment(comments: Readonly[], specificationBody: string, allComments: AllComments) { + async _processComment( + comments: Readonly[], + priority: number | undefined, + specificationBody: string, + allComments: AllComments + ) { const commentsWithScore: GithubCommentScore[] = [...comments]; const { commentsToEvaluate, prCommentsToEvaluate } = this._splitCommentsByPrompt(commentsWithScore); @@ -126,7 +135,7 @@ export class ContentEvaluatorModule implements Module { currentComment.score = { ...(currentComment.score || { multiplier: 0 }), - relevance: new Decimal(currentRelevance).toNumber(), + relevance: new Decimal(currentRelevance).mul(priority ?? 1).toNumber(), reward: currentReward.toNumber(), }; }