Support newer OpenAI models

This commit is contained in:
Milo Toor 2025-03-07 13:12:25 -08:00
parent a9a064dfa1
commit 64a327d459
5 changed files with 5705 additions and 2490 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
node_modules node_modules
.idea .idea
lib/**/* lib/**/*
.yarn

5588
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -110,6 +110,11 @@ ${chunk.changes
`; `;
} }
function modelSupportsJsonResponse(model: string): boolean {
const supportedModels = ["gpt-4o", "gpt-4o-mini", "gpt-4.5-preview", "o3-mini", "o1", "o1-mini"];
return supportedModels.includes(model);
}
async function getAIResponse(prompt: string): Promise<Array<{ async function getAIResponse(prompt: string): Promise<Array<{
lineNumber: string; lineNumber: string;
reviewComment: string; reviewComment: string;
@ -127,7 +132,7 @@ async function getAIResponse(prompt: string): Promise<Array<{
const response = await openai.chat.completions.create({ const response = await openai.chat.completions.create({
...queryConfig, ...queryConfig,
// return JSON if the model supports it: // return JSON if the model supports it:
...(OPENAI_API_MODEL === "gpt-4-1106-preview" ...(modelSupportsJsonResponse(OPENAI_API_MODEL)
? { response_format: { type: "json_object" } } ? { response_format: { type: "json_object" } }
: {}), : {}),
messages: [ messages: [

View file

@ -1,6 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", "target": "es6",
"lib": ["esnext"],
"module": "commonjs", "module": "commonjs",
"outDir": "./lib", "outDir": "./lib",
"rootDir": "./src", "rootDir": "./src",