Skip to content

Commit

Permalink
fix: enhance error logging and update regex for comments
Browse files Browse the repository at this point in the history
Add missing data to error log and change regex for JSON processing.
  • Loading branch information
gentlementlegen committed Nov 10, 2024
1 parent bf09a15 commit 2ccdc8a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ export class ContentEvaluatorModule extends BaseModule {
);

if (Object.keys(relevancesByAi).length !== commentsToEvaluate.length + prCommentsToEvaluate.length) {
throw this.context.logger.fatal("Relevance / Comment length mismatch!", { relevancesByAi, commentsToEvaluate });
throw this.context.logger.fatal("Relevance / Comment length mismatch!", {
relevancesByAi,
commentsToEvaluate,
prCommentsToEvaluate,
});
}

for (const currentComment of commentsWithScore) {
Expand Down
19 changes: 10 additions & 9 deletions src/web/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,22 @@ app.use(
// Fakes OpenAi routes
app.post("/openai/*", async (c) => {
const text = await c.req.json();
const regex = /START EVALUATING:\s*\[([\s\S]*?)]/g;
const regex = /JSON response should equal exactly (\d+)/g;

const comments: { id: string; comment: string; author: string }[] = [];

if ("messages" in text) {
let match;
while ((match = regex.exec(text.messages[0].content)) !== null) {
const jsonArray = JSON.parse(`[${match[1]}]`);
jsonArray.forEach((item: { id: string; comment: string; author: string }) => {
comments.push({
id: item.id,
comment: item.comment,
author: item.author,
});
});
const length = JSON.parse(`[${match[1]}]`);

comments.push(
...Array.from({ length }, (item, i) => ({
id: i.toString(),
comment: "Generic comment",
author: "Generic author",
}))
);
}
}

Expand Down

0 comments on commit 2ccdc8a

Please sign in to comment.