Skip to content

Commit

Permalink
feat: multiply conv reward with priority for higher reward
Browse files Browse the repository at this point in the history
  • Loading branch information
ishowvel committed Oct 29, 2024
1 parent 2098c06 commit 71a5c1a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
42 changes: 42 additions & 0 deletions src/helpers/label-price-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 12 additions & 3 deletions src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
)
);
Expand All @@ -99,7 +103,12 @@ export class ContentEvaluatorModule implements Module {
return reward;
}

async _processComment(comments: Readonly<GithubCommentScore>[], specificationBody: string, allComments: AllComments) {
async _processComment(
comments: Readonly<GithubCommentScore>[],
priority: number | undefined,
specificationBody: string,
allComments: AllComments
) {
const commentsWithScore: GithubCommentScore[] = [...comments];
const { commentsToEvaluate, prCommentsToEvaluate } = this._splitCommentsByPrompt(commentsWithScore);

Expand All @@ -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(),
};
}
Expand Down

0 comments on commit 71a5c1a

Please sign in to comment.