mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-21 01:56:47 +00:00
Use GPT-3.5
This commit is contained in:
parent
a9a064dfa1
commit
62c5563c93
3 changed files with 1322 additions and 1307 deletions
14
dist/index.js
vendored
14
dist/index.js
vendored
|
@ -146,17 +146,25 @@ function getAIResponse(prompt) {
|
||||||
presence_penalty: 0,
|
presence_penalty: 0,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = yield openai.chat.completions.create(Object.assign(Object.assign(Object.assign({}, queryConfig), (OPENAI_API_MODEL === "gpt-4-1106-preview"
|
const response = yield openai.chat.completions.create(Object.assign(Object.assign({}, queryConfig), { messages: [
|
||||||
? { response_format: { type: "json_object" } }
|
|
||||||
: {})), { messages: [
|
|
||||||
{
|
{
|
||||||
role: "system",
|
role: "system",
|
||||||
content: prompt,
|
content: prompt,
|
||||||
},
|
},
|
||||||
] }));
|
] }));
|
||||||
|
// Log the raw response for debugging
|
||||||
|
console.log('Raw response:', JSON.stringify(response, null, 2));
|
||||||
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "{}";
|
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "{}";
|
||||||
|
// Attempt to parse JSON
|
||||||
|
try {
|
||||||
return JSON.parse(res).reviews;
|
return JSON.parse(res).reviews;
|
||||||
}
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error("Failed to parse JSON:", e);
|
||||||
|
console.error("Response content:", res);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
return null;
|
return null;
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
15
src/main.ts
15
src/main.ts
|
@ -126,10 +126,6 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
||||||
try {
|
try {
|
||||||
const response = await openai.chat.completions.create({
|
const response = await openai.chat.completions.create({
|
||||||
...queryConfig,
|
...queryConfig,
|
||||||
// return JSON if the model supports it:
|
|
||||||
...(OPENAI_API_MODEL === "gpt-4-1106-preview"
|
|
||||||
? { response_format: { type: "json_object" } }
|
|
||||||
: {}),
|
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: "system",
|
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() || "{}";
|
const res = response.choices[0].message?.content?.trim() || "{}";
|
||||||
|
|
||||||
|
// Attempt to parse JSON
|
||||||
|
try {
|
||||||
return JSON.parse(res).reviews;
|
return JSON.parse(res).reviews;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to parse JSON:", e);
|
||||||
|
console.error("Response content:", res);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue