Skip to content

Commit

Permalink
[feature]: Instruction table with metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgobes committed Dec 20, 2023
1 parent a7bdfc1 commit 416ceb3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo

certificates
certificates
.env*.local
4 changes: 3 additions & 1 deletion app/api/webhook/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export const POST = async (req: Request) => {
if (!customer) return new Response('Could not find customer', {status: 500})

const {id: customerId, usage, usageLimit, usageWarned, projects} = customer
const instructions = projects?.[0]?.customInstructions || ''
const instructions =
projects?.[0]?.customInstructions.map(ci => ci.content).join('. ') || ''

// Get GitHub app instance access token
const app = new App({
Expand Down Expand Up @@ -305,6 +306,7 @@ Your instructions: ${instructions || 'do nothing'}.
issueId: issue?.node_id,
pullUrl: issue?.pull_request?.url || pr?.url || null,
allLabels,
comment,
beta
})

Expand Down
Binary file modified bun.lockb
Binary file not shown.
12 changes: 11 additions & 1 deletion lib/agents/maige.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function maige({
issueId,
pullUrl,
allLabels,
comment,
beta
}: {
input: string
Expand All @@ -37,11 +38,20 @@ export async function maige({
issueId?: string
pullUrl?: string
allLabels: any[]
comment: any
beta?: boolean
}) {
const tools = [
labelTool({octokit, allLabels, issueId}),
updateInstructionsTool({octokit, prisma, customerId, issueId, repoFullName}),
updateInstructionsTool({
octokit,
prisma,
customerId,
issueId,
repoFullName,
instructionCreator: comment.user.login,
instructionCommentLink: comment.html_url
}),
githubTool({octokit}),
codebaseSearch({customerId, repoFullName}),
...(beta ? [dispatchEngineer({issueNumber, repoFullName, customerId})] : []),
Expand Down
22 changes: 16 additions & 6 deletions lib/tools/updateInstructions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {PrismaClient} from '@prisma/client'
import {DynamicStructuredTool} from 'langchain/tools'
import {z} from 'zod'
import {addComment} from '~/utils/github'
Expand All @@ -7,27 +8,36 @@ export default function updateInstructions({
customerId,
repoFullName,
issueId,
instructionCreator,
instructionCommentLink,
octokit
}: {
prisma: any
prisma: PrismaClient
octokit: any
issueId: string
customerId: string
repoFullName: string
instructionCreator: string
instructionCommentLink: string
}) {
return new DynamicStructuredTool({
description:
'User will explicitly ask for custom instructions to be updated.',
func: async ({newInstructions}) => {
const res = await prisma.project.update({
where: {
customerId_name: {
const project = (
await prisma.project.findMany({
where: {
customerId,
name: repoFullName.split('/')[1]
}
},
})
)[0]
const res = await prisma.instruction.create({
data: {
customInstructions: newInstructions
projectId: project.id,
content: newInstructions,
creatorUsername: instructionCreator,
githubCommentLink: instructionCommentLink
}
})

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@typescript-eslint/parser": "^6.11.0",
"autoprefixer": "^10.4.16",
"bun-types": "^1.0.12",
"dotenv-cli": "5.0.0",
"eslint": "^8.53.0",
"npm-check-updates": "^16.14.6",
"postcss": "^8.4.31",
Expand All @@ -53,7 +54,7 @@
"bleed": "ncu -u && bun i",
"build": "next build",
"db:push": "prisma db push",
"db:studio": "prisma studio",
"db:studio": "dotenv -e .env.local -- prisma studio",
"dev": "next dev",
"format": "prettier --write .",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.json,.ts,.tsx",
Expand Down
18 changes: 15 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ model Project {
id String @id @default(cuid())
name String
customInstructions String @default("") @db.Text
customerId String
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
createdAt DateTime @default(now())
customInstructions Instruction[]
@@unique([customerId, name])
@@index([customerId])
}

model Instruction {
id String @id @default(cuid())
projectId String
content String @db.Text
creatorUsername String?
githubCommentLink String?
createdAt DateTime @default(now())
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@index([projectId])
}

0 comments on commit 416ceb3

Please sign in to comment.