Skip to content

Commit

Permalink
chore: gpt-4o only
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Jun 14, 2024
1 parent f523f78 commit e72afd5
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Decimal from "decimal.js";
import { encodingForModel } from "js-tiktoken";
import OpenAI from "openai";
import configuration from "../configuration/config-reader";
import { OPENAI_API_KEY } from "../configuration/constants";
Expand Down Expand Up @@ -50,7 +49,7 @@ export class ContentEvaluatorModule implements Module {
async _processComment(comments: Readonly<GithubCommentScore>[], specificationBody: string) {
const commentsWithScore: GithubCommentScore[] = [...comments];
const commentsBody = commentsWithScore.map((comment) => comment.content);
const relevance = await this._sampleRelevanceScoreResults(specificationBody, commentsBody);
const relevance = await this._evaluateComments(specificationBody, commentsBody);

if (relevance.length !== commentsWithScore.length) {
console.error("Relevance / Comment length mismatch! Skipping.");
Expand All @@ -71,12 +70,12 @@ export class ContentEvaluatorModule implements Module {
return commentsWithScore;
}

async _evaluateComments(specification: string, comments: string[]): Promise<number[]> {
async _evaluateComments(specification: string, comments: string[]): Promise<Decimal[]> {
const prompt = this._generatePrompt(specification, comments);

try {
const response: OpenAI.Chat.ChatCompletion = await this._openAi.chat.completions.create({
model: this._getOptimalModel(prompt),
model: "gpt-4o",
messages: [
{
role: "system",
Expand All @@ -99,24 +98,6 @@ export class ContentEvaluatorModule implements Module {
}
}

_getOptimalModel(prompt: string) {
const encoder = encodingForModel("gpt-4o");
const totalSumOfTokens = encoder.encode(prompt).length;

if (totalSumOfTokens <= 4097) {
return "gpt-3.5-turbo";
} else if (totalSumOfTokens <= 16385) {
return "gpt-3.5-turbo-16k"; // gpt-4o?
} else {
console.warn("Backup plan for development purposes only, but using gpt-4 due to huge context size");
return "gpt-4o";
}
}

async _sampleRelevanceScoreResults(specification: string, comments: string[]) {
return await this._evaluateComments(specification, comments);
}

_generatePrompt(issue: string, comments: string[]) {
if (!issue?.length) {
throw new Error("Issue specification comment is missing or empty");
Expand Down

0 comments on commit e72afd5

Please sign in to comment.