Update the package correctly

This commit is contained in:
Aymeric Gaurat-Apelli 2024-10-02 16:02:33 +10:00
commit d1491f0083
3 changed files with 1304 additions and 1310 deletions

2600
dist/index.js vendored

File diff suppressed because it is too large Load diff

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -140,16 +140,8 @@ async function getAIResponse(prompt: string): Promise<Array<{
}); });
const res = response.choices[0].message?.content?.trim() || "{}"; const res = response.choices[0].message?.content?.trim() || "{}";
// Remove lines ```json and ``` from the response console.log("AI Response:", res);
const jsonStart = res.indexOf("{"); return JSON.parse(res).reviews;
const jsonEnd = res.lastIndexOf("}");
if (jsonStart === -1 || jsonEnd === -1) {
console.error("Error: JSON not found in response: " + res);
return null;
}
const jsonRes = res.substring(jsonStart, jsonEnd + 1);
console.log("AI Response:", jsonRes);
return JSON.parse(jsonRes).reviews;
} catch (error) { } catch (error) {
console.error("Error:", error); console.error("Error:", error);
return null; return null;