Skip to content

Commit

Permalink
fix summary
Browse files Browse the repository at this point in the history
  • Loading branch information
bemijonathan committed Oct 7, 2023
1 parent c1236d6 commit ce37b9d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function run(): Promise<void> {
const summary = await summarizeChanges(changes)

if (!summary) {
Logger.warn('Could not summarize changes, exiting')
Logger.warn('Summary is empty, exiting')
return
}

Expand Down
29 changes: 2 additions & 27 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,8 @@ Be specific and descriptive, accurately identifying the affected files and lines
Present your summary in a clear and concise manner, ensuring readability and comprehension for all stakeholders involved in the code review process.
Length: Aim for a summary of around 3-5 sentences.
Style: Maintain a professional and objective tone in your review, emphasizing the technical aspects and impact of the changes rather than personal opinions.
Formatting: Use Markdown to format your summary.
e.g.
## Title
# Issue Reference
- This PR fixes/closes/relates to issue #[issue number]
## Description
- Detailed explanation of what this PR does and why it's needed.
## Why?
- Explanation of the reasoning behind the changes.
## Testing Scope
- Scenarios to be tested based on the changes of this PR e.g table was updated so all CRUD operations should be tested.
## Notable Changes
- if the new changes has a significant change in the logic please add a short table of the old and new logic and ask
if the new logic is correct or not.
-----------------------------
{diff}
`

export const generatePrompt = () => { }
31 changes: 21 additions & 10 deletions src/steps/summarize-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,48 @@ export async function summarizeChanges(
diff: string
): Promise<string | undefined> {
try {
Logger.log('summarizing changes')

const openAiKey = core.getInput('openAIKey')

const model = new OpenAI(
{ temperature: 0, openAIApiKey: openAiKey },
{ temperature: 0.7, openAIApiKey: openAiKey, "model": "davinci" },
)
Logger.log('created model')

const textSplitter = new RecursiveCharacterTextSplitter({
chunkSize: 1000,
separators: ['diff --git'],
chunkOverlap: 0,
keepSeparator: true
})

Logger.log('created text splitter')

const docs = await textSplitter.createDocuments([diff])
const basePromptTemplate = PromptTemplate.fromTemplate(prompt)

const basePromptTemplate = new PromptTemplate({
template: prompt,
inputVariables: ["diff"]
})

Logger.log('created prompt template')
const chain = loadSummarizationChain(model, {
prompt: basePromptTemplate,
type: "refine",
verbose: true,
type: 'stuff'
refinePrompt: basePromptTemplate
})

Logger.log('loaded summarization chain')

const res = await chain.call({
input_documents: docs
input_documents: docs,
diff: diff
})

Logger.log('summarized changes')
console.log({ res })

return res.output.join('\n')
return res.output_text
} catch (e) {
Logger.log('error summarizing changes')
console.log(e)
Logger.log(e)
}
}

0 comments on commit ce37b9d

Please sign in to comment.