Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32,050 changes: 16,828 additions & 15,222 deletions lib/index.js

Large diffs are not rendered by default.

5,965 changes: 5,965 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"@octokit/core": "^4.1.0",
"@octokit/plugin-paginate-rest": "^5.0.1",
"@octokit/rest": "^19.0.5",
"openai": "^3.1.0"
"openai": "^4.86.2"
}
}
16 changes: 8 additions & 8 deletions src/commitSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ async function getOpenAICompletion(
throw new Error("OpenAI query too big");
}

const response = await openai.createCompletion({
const response = await openai.chat.completions.create({
model: MODEL_NAME,
prompt: openAIPrompt,
messages: [
{ role: 'user', content: openAIPrompt }
],
max_tokens: MAX_TOKENS,
temperature: TEMPERATURE,
});

if (
response.data.choices !== undefined &&
response.data.choices.length > 0
) {

if (response.choices !== undefined && response.choices.length > 0) {
completion = postprocessSummary(
diffResponse.data.files.map((file: any) => file.filename),
response.data.choices[0].text ?? "Error: couldn't generate summary",
response.choices[0].message?.content ?? "Error: couldn't generate summary",
diffMetadata
);
}

} catch (error) {
console.error(error);
}
Expand Down
17 changes: 8 additions & 9 deletions src/filesSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@ async function getOpenAISummaryForFile(
throw new Error("OpenAI query too big");
}

const response = await openai.createCompletion({
const response = await openai.chat.completions.create({
model: MODEL_NAME,
prompt: openAIPrompt,
messages: [
{ role: 'user', content: openAIPrompt }
],
max_tokens: MAX_TOKENS,
temperature: TEMPERATURE,
});
if (
response.data.choices !== undefined &&
response.data.choices.length > 0
) {
return (
response.data.choices[0].text ?? "Error: couldn't generate summary"
);

if (response.choices !== undefined && response.choices.length > 0) {
return response.choices[0].message?.content ?? "Error: couldn't generate summary";
}

} catch (error) {
console.error(error);
}
Expand Down
9 changes: 4 additions & 5 deletions src/openAi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Configuration, OpenAIApi } from "openai";
import OpenAI from 'openai';

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
export const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY, // This is the default and can be omitted
});

export const MAX_OPEN_AI_QUERY_LENGTH = 20000;
export const MODEL_NAME = "text-davinci-003";
export const MODEL_NAME = "gpt-4o-mini";
export const TEMPERATURE = 0.5;
export const MAX_TOKENS = 512;

export const openai = new OpenAIApi(configuration);
10 changes: 7 additions & 3 deletions src/summarizePr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ export async function summarizePr(
}

try {
const response = await openai.createCompletion({
const response = await openai.chat.completions.create({
model: MODEL_NAME,
prompt: openAIPrompt,
messages: [
{ role: 'user', content: openAIPrompt }
],
max_tokens: MAX_TOKENS,
temperature: TEMPERATURE,
});
return response.data.choices[0].text ?? "Error: couldn't generate summary";

return response.choices[0].message?.content ?? "Error: couldn't generate summary";
} catch (error) {
console.error(error);
return "Error: couldn't generate summary";
}

}
1,165 changes: 673 additions & 492 deletions yarn.lock

Large diffs are not rendered by default.