Merge pull request #5 from arunsnt/use-gpt-3-5

Use GPT-3.5
This commit is contained in:
Arun Murugan 2024-05-21 14:14:11 -04:00 committed by GitHub
commit ff8ad8d15b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 1322 additions and 1307 deletions

2610
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

@ -126,10 +126,6 @@ async function getAIResponse(prompt: string): Promise<Array<{
try {
const response = await openai.chat.completions.create({
...queryConfig,
// return JSON if the model supports it:
...(OPENAI_API_MODEL === "gpt-4-1106-preview"
? { response_format: { type: "json_object" } }
: {}),
messages: [
{
role: "system",
@ -138,8 +134,19 @@ async function getAIResponse(prompt: string): Promise<Array<{
],
});
// Log the raw response for debugging
console.log('Raw response:', JSON.stringify(response, null, 2));
const res = response.choices[0].message?.content?.trim() || "{}";
return JSON.parse(res).reviews;
// Attempt to parse JSON
try {
return JSON.parse(res).reviews;
} catch (e) {
console.error("Failed to parse JSON:", e);
console.error("Response content:", res);
return null;
}
} catch (error) {
console.error("Error:", error);
return null;