diff --git a/src/index.ts b/src/index.ts index 40aa32c..b876eb9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,7 +34,7 @@ export async function run(): Promise { const summary = await summarizeChanges(changes) if (!summary) { - Logger.warn('Could not summarize changes, exiting') + Logger.warn('Summary is empty, exiting') return } diff --git a/src/prompts.ts b/src/prompts.ts index 3d2fbd9..eaab260 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -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 = () => { } diff --git a/src/steps/summarize-changes.ts b/src/steps/summarize-changes.ts index 42d94f6..c28747d 100644 --- a/src/steps/summarize-changes.ts +++ b/src/steps/summarize-changes.ts @@ -10,37 +10,48 @@ export async function summarizeChanges( diff: string ): Promise { 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) } }