-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Reviewer agent to summarize PR. (#54)
* Add reviewer agent for pull request
- Loading branch information
Showing
11 changed files
with
261 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {initializeAgentExecutorWithOptions} from 'langchain/agents' | ||
import {ChatOpenAI} from 'langchain/chat_models/openai' | ||
import {SerpAPI} from 'langchain/tools' | ||
import env from '~/env.mjs' | ||
import {prComment} from '~/tools/prComment' | ||
import {isDev} from '~/utils' | ||
|
||
const model = new ChatOpenAI({ | ||
modelName: 'gpt-4-1106-preview', | ||
openAIApiKey: env.OPENAI_API_KEY, | ||
temperature: 0.3 | ||
}) | ||
|
||
export default async function reviewer({ | ||
input, | ||
octokit, | ||
pullId | ||
}: { | ||
input: string | ||
octokit: any | ||
pullId: string | ||
}) { | ||
const tools = [new SerpAPI(), prComment({octokit, pullId})] | ||
|
||
const prefix = ` | ||
You are senior engineer reviewing a Pull Request in GitHub made by a junior engineer. | ||
You MUST leave a comment on the PR according to the user's instructions using the prComment function. | ||
Format your answer beautifully using markdown suitable for GitHub. | ||
DO NOT use any emojis or non-Ascii characters. | ||
{agent_scratchpad} | ||
`.replaceAll('\n', ' ') | ||
|
||
const executor = await initializeAgentExecutorWithOptions(tools, model, { | ||
agentType: 'openai-functions', | ||
returnIntermediateSteps: isDev, | ||
handleParsingErrors: true, | ||
verbose: false, | ||
agentArgs: { | ||
prefix | ||
} | ||
}) | ||
|
||
const result = await executor.call({input}) | ||
const {output} = result | ||
|
||
return output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {DynamicStructuredTool} from 'langchain/tools' | ||
import {z} from 'zod' | ||
import engineer from '~/agents/engineer' | ||
/** | ||
* Execute a shell command | ||
*/ | ||
export default function dispatchEngineer({ | ||
octokit, | ||
prisma, | ||
customerId, | ||
repoName | ||
}: { | ||
octokit: any | ||
prisma: any | ||
customerId: string | ||
repoName: string | ||
}) { | ||
return new DynamicStructuredTool({ | ||
description: 'Dispatch an engineer to work on an issue', | ||
func: async ({input}) => { | ||
console.log('DISPATCHING ENGINEER') | ||
engineer({ | ||
input, | ||
octokit, | ||
prisma, | ||
customerId, | ||
repoName | ||
}) | ||
// await new Promise(resolve => setTimeout(resolve, 1000)) | ||
return 'dispatched' | ||
}, | ||
name: 'dispatchEngineer', | ||
schema: z.object({ | ||
input: z | ||
.string() | ||
.describe('specific, detailed instructions for the engineer.') | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {DynamicStructuredTool} from 'langchain/tools' | ||
import {z} from 'zod' | ||
import {addComment} from '~/utils/github' | ||
|
||
/** | ||
* Comment on an issue | ||
*/ | ||
export function prComment({octokit, pullId}: {octokit: any; pullId: string}) { | ||
return new DynamicStructuredTool({ | ||
description: 'Adds a comment to a PR', | ||
func: async ({comment, severity}) => { | ||
const footer = `By [Maige](https://maige.app). How's my driving?` | ||
const res = await addComment({ | ||
octokit, | ||
issueId: pullId, | ||
comment: `${comment}\nThis is a Level ${severity} problem.\n\n${footer}` | ||
}) | ||
return JSON.stringify(res) | ||
}, | ||
name: 'prComment', | ||
schema: z.object({ | ||
comment: z.string().describe('The comment to add'), | ||
severity: z | ||
.number() | ||
.optional() | ||
.describe('The severity of the needed fix on a scale of 1-5') | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.