-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support latest gpt 4 #32
Conversation
@@ -1,6 +1,6 @@ | |||
import { readFileSync } from "fs"; | |||
import * as core from "@actions/core"; | |||
import { Configuration, OpenAIApi } from "openai"; | |||
import OpenAI from "openai"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly importing OpenAI
without destructuring may lead to potential issues if the library expects specific imports. Ensure that the OpenAI
import aligns with the library's updated export structure for gpt-4-1106-preview and json mode.
@@ -98,7 +96,7 @@ async function getBaseAndHeadShas( | |||
|
|||
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { | |||
return `Your task is to review pull requests. Instructions: | |||
- Provide the response in following JSON format: [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}] | |||
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON format provided in the updated line does not match the standard JSON array format. It should be an array of objects within square brackets []
.
...queryConfig, | ||
// return JSON if the model supports it: | ||
...(OPENAI_API_MODEL === "gpt-4-1106-preview" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response_format
object structure seems incorrect. The response_format
should be a string, not an object. It should be 'response_format': 'json'
if you want to specify JSON format.
@@ -152,8 +154,8 @@ async function getAIResponse(prompt: string): Promise<Array<{ | |||
], | |||
}); | |||
|
|||
const res = response.data.choices[0].message?.content?.trim() || "[]"; | |||
return JSON.parse(res); | |||
const res = response.choices[0].message?.content?.trim() || "{}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback value for res
should be an empty array []
instead of an empty object {}
to match the expected return type of the function.
const res = response.data.choices[0].message?.content?.trim() || "[]"; | ||
return JSON.parse(res); | ||
const res = response.choices[0].message?.content?.trim() || "{}"; | ||
return JSON.parse(res).reviews; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the property reviews
exists on the parsed object to avoid potential runtime errors. Consider adding a check before accessing reviews
property.
9b70faa
to
82c725a
Compare
82c725a
to
5c13a26
Compare
Hey @villesau, thanks for adding this but it doesn't seem to work. I think it worked first time, but later on I get the same error as #56
|
@lukehollenback I also tried your branch #57, still the same error
|
If you add this prompt after |
Support gpt-4-1106-preview and json mode