Skip to content

Commit

Permalink
fix: update regex and parsing for OpenAI responses
Browse files Browse the repository at this point in the history
Changed regex pattern and implemented better parsing logic for comments.
  • Loading branch information
gentlementlegen committed Nov 8, 2024
1 parent 8ff3a94 commit 93b33df
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/web/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ app.use(

app.post("/openai/*", async (c) => {
const text = await c.req.json();
const regex = /{\s*"id":\s*(\d+),\s*"comment":\s*"([^"]*)",\s*"author":\s*"([^"]*)"\s*}/g;
const regex = /START EVALUATING:\s*\[([\s\S]*?)]/g;

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

if ("messages" in text) {
let match;
while ((match = regex.exec(text.messages[0].content)) !== null) {
comments.push({
id: parseInt(match[1], 10),
comment: match[2],
author: match[3],
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,
});
});
}
}
Expand Down

0 comments on commit 93b33df

Please sign in to comment.