Skip to content

Commit

Permalink
fix: 优化 json 解析
Browse files Browse the repository at this point in the history
  • Loading branch information
Lydanne committed May 31, 2024
1 parent fda78af commit 76e64f7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/diffRank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ export async function diffRank(source: string, target: string, options: any) {
const content = "代码片段:\n\n" + md.join("\n");
const response = await gpt.run(content, options.model);

const matchJSON = response?.match(/\[[\s\S]*?\]/g);
const matchJSON = response?.match(/\{[\s\S]+?\}/g);

const result = matchJSON?.reduce((acc, cur) => {
try {
const json = JSON.parse(cur);
acc.push(...json);
} catch (error) {
acc.push(json);
} catch (e) {
console.log("### ERROR ###");
console.log(cur);
console.log(response);
console.log("Current:", cur);
console.log("Response:", response);
}

return acc;
Expand Down

0 comments on commit 76e64f7

Please sign in to comment.