Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arihan/mar 50 dashboard usage page #80

Merged
merged 60 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f5b2d99
feat: create base data-table
arihanv Jan 6, 2024
44aca4e
feat: add fulltext search
arihanv Jan 14, 2024
68d71bb
style: add and customize shadcn table
arihanv Jan 14, 2024
b94e07e
feat: create ssr table to show usage data
arihanv Jan 14, 2024
d97b266
feat: create search for actions column
arihanv Jan 14, 2024
f580fc2
feat: loading state for usage table
arihanv Jan 14, 2024
447032c
feat: add sort order
arihanv Jan 14, 2024
e7cff9d
style: add hover effect on repo nav
arihanv Jan 14, 2024
744f932
fix: add @radix-ui/react-checkbox
arihanv Jan 14, 2024
ccd15b7
install: tremor and configure styles
arihanv Jan 14, 2024
d0a709a
feat: display example charts
arihanv Jan 14, 2024
e157952
feat: log usage to prisma db
arihanv Jan 14, 2024
23ec889
fix: page scrolling issues
arihanv Jan 14, 2024
57898e3
style: responsiveness
arihanv Jan 15, 2024
ed81282
feat: add shadcn popover
arihanv Jan 15, 2024
733eeb6
feat: server actions for custom instructions
arihanv Jan 15, 2024
c2b1805
feat: add new instruction
arihanv Jan 15, 2024
5043f9e
feat: add create and delete custom instructions
arihanv Jan 15, 2024
eebb6c3
feat: add prompt and completion tokens
arihanv Jan 16, 2024
210f369
feat: display charts
arihanv Jan 16, 2024
a445787
feat: log completion and prompt tokens
arihanv Jan 16, 2024
e00667a
feat: compute tokens column
arihanv Jan 16, 2024
3837018
refactor: render chart and table efficiently
arihanv Jan 18, 2024
1e0167b
style: chart links
arihanv Jan 18, 2024
511d899
feat: add and sort by total tokens
arihanv Jan 18, 2024
4eceec7
fix: underline on usage title
arihanv Jan 18, 2024
15d887d
don't error on no description
DexterStorey Jan 3, 2024
1ed7dbb
format + lint
DexterStorey Jan 13, 2024
21cc5e3
format, lint
DexterStorey Jan 13, 2024
b6329c2
env cleanup
DexterStorey Jan 13, 2024
0a15b50
env documentation
DexterStorey Jan 13, 2024
27e14fc
sketchy set response types
DexterStorey Jan 13, 2024
03129cf
Move dashboard auth to GH App. Re-style login page.
tedspare Jan 13, 2024
fbcf487
GitHub App authentication for enginner
Jan 13, 2024
c122237
remove usage of env.GITHUB_AUTH_TOKEN across app
Jan 13, 2024
8a3acfd
Bump repo count
tedspare Jan 13, 2024
01ac147
Clean up dashboard styling
tedspare Jan 13, 2024
7500330
Update readme
sarimrmalik Jan 16, 2024
faa95cd
Update README.md
tedspare Jan 16, 2024
fbb0159
Update README.md
tedspare Jan 16, 2024
4c786cc
Update schema.prisma
tedspare Jan 16, 2024
268759e
feat: update schema
arihanv Jan 17, 2024
6b9dddc
feat: add direct_url to env config
arihanv Jan 17, 2024
75922f2
fix: styling issues
arihanv Jan 17, 2024
c44fb25
feat: create feedback model
arihanv Jan 17, 2024
b8271cc
feat: flow to submit feedback with toast
arihanv Jan 17, 2024
125834f
Arihan/mar 60 create general feedback flow UI for it (#83)
arihanv Jan 18, 2024
e82a2bb
Merge branch 'staging' into arihan/mar-50-dashboard-usage-page
arihanv Jan 19, 2024
72b593c
clean: remove unused files, code design
arihanv Jan 19, 2024
2d6811e
clean: remove comments
arihanv Jan 19, 2024
50f39d5
fix: feedback component position
arihanv Jan 19, 2024
d9fe088
clean: lint and format
arihanv Jan 19, 2024
cc9586f
clean: rename to chart
arihanv Jan 19, 2024
5e82891
fix: add tremor as a dep
arihanv Jan 19, 2024
97ec5d6
fix: add dep
arihanv Jan 19, 2024
5d867b9
Remove unused env var
tedspare Jan 19, 2024
9f3e163
Memoize instruction edit functions
tedspare Jan 19, 2024
342647c
Combine DB queries
tedspare Jan 19, 2024
b9d1aa5
Parametrize chart dates
tedspare Jan 19, 2024
775ea60
Hide timing decimals
tedspare Jan 19, 2024
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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ Create a GitHub App for webhooks and repo access. Populate your **.env** with th
2. Copy your app name, ID, and client secret. Add these to your **.env**.
3. Callback URL: nGrok URL + GitHub auth endpoint eg. `https://abc.ngrok.app/api/auth/callback/github`
4. Webhook URL: nGrok URL + handler path eg. `https://abc.ngrok.app/api/webhook/github`.
6. Webhook secret: generate this with `openssl rand -hex 32`. Add it to your **.env**.
7. Permissions: toggle **Issue: Read & Write** and **Pull Request: Read & Write**.
8. Events: toggle **issues**, **issue comments**, and **pull requests**.
9. Private key: generate a private key. Download it. Run the following command ([source](https://github.com/gr2m/universal-github-app-jwt?tab=readme-ov-file#converting-pkcs1-to-pkcs8)) to convert it to the right format:
5. Webhook secret: generate this with `openssl rand -hex 32`. Add it to your **.env**.
6. Permissions: toggle **Issue: Read & Write** and **Pull Request: Read & Write**.
7. Events: toggle **issues**, **issue comments**, and **pull requests**.
8. Private key: generate a private key. Download it. Run the following command ([source](https://github.com/gr2m/universal-github-app-jwt?tab=readme-ov-file#converting-pkcs1-to-pkcs8)) to convert it to the right format:

```sh
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in private-key.pem -out private-key-pkcs8.key
```

then copy **private-key-pkcs8.key**'s text contents to your **.env**.

## Dive In
Expand Down
5 changes: 4 additions & 1 deletion app/api/webhook/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export const POST = async (req: Request) => {
name: payload?.repository?.name
},
select: {
id: true,
name: true,
customInstructions: true
}
Expand All @@ -210,6 +211,8 @@ export const POST = async (req: Request) => {
const instructions =
projects?.[0]?.customInstructions.map(ci => ci.content).join('. ') || ''

const projectId = projects?.[0]?.id

// Get GitHub app instance access token
const app = new App({
appId: env.GITHUB_APP_ID || '',
Expand Down Expand Up @@ -299,8 +302,8 @@ Your instructions: ${instructions || 'do nothing'}.
await maige({
input: prompt,
octokit,
prisma,
customerId,
projectId,
repoFullName: `${owner}/${name}`,
issueNumber: issue?.number,
issueId: issue?.node_id,
Expand Down
35 changes: 35 additions & 0 deletions app/dashboard/(base)/usage/[[...metric]]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {notFound} from 'next/navigation'
import z from 'zod'
import Charts from '~/components/dashboard/usage/charts'
import ChartsLinks from '~/components/dashboard/usage/charts-links'

const paramsSchema = z.enum(['runs', 'tokens'])

export default async function RootLayout({
children,
params
}: {
children: React.ReactNode
params: {
metric: string[] | undefined
}
}) {
if (
params.metric &&
(params.metric.length > 1 ||
!paramsSchema.safeParse(params?.metric[0]).success)
)
return notFound()

const route = params.metric ? params.metric[0] : ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautifully simple


return (
<div className='space-y-2'>
<ChartsLinks route={route} />
<div className='space-y-5'>
<Charts route={route} />
{children}
</div>
</div>
)
}
12 changes: 12 additions & 0 deletions app/dashboard/(base)/usage/[[...metric]]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Skeleton} from '~/components/ui/skeleton'

type Props = {}

export default function Loading({}: Props) {
return (
<div className='space-y-2'>
<Skeleton className='h-10' />
<Skeleton className='h-56' />
</div>
)
}
20 changes: 20 additions & 0 deletions app/dashboard/(base)/usage/[[...metric]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import UsageTable from '~/components/dashboard/usage/table-wrapper'

export default async function Usage({
searchParams,
params
}: {
searchParams: {[key: string]: string | string[] | undefined}
params: {
metric: string[] | undefined
}
}) {
const route = params.metric ? params.metric[0] : ''

return (
<UsageTable
route={route}
searchParams={searchParams}
/>
)
}
5 changes: 0 additions & 5 deletions app/dashboard/(base)/usage/page.tsx

This file was deleted.

26 changes: 26 additions & 0 deletions app/dashboard/repo/[projectId]/instructions/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use server'

import {revalidatePath} from 'next/cache'
import {redirect} from 'next/navigation'

export async function createInstruction(projectId: string, content: string) {
const req = await prisma.instruction.create({
data: {
projectId: projectId,
content: content,
creatorUsername: 'Dashboard'
}
})
revalidatePath(`/dashboard/repo/${projectId}/instructions`)
redirect(`/dashboard/repo/${projectId}/instructions#${req.id}`)
}

export async function deleteInstruction(projectId: string, id: string) {
await prisma.instruction.delete({
where: {
id: id
}
})
revalidatePath(`/dashboard/repo/${projectId}/instructions`)
redirect(`/dashboard/repo/${projectId}/instructions`)
}
7 changes: 6 additions & 1 deletion app/dashboard/repo/[projectId]/instructions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ async function InstructionsWrapper({projectId}: {projectId: string}) {
}
})

return <Instructions instructions={instructions} />
return (
<Instructions
projectId={projectId}
instructions={instructions}
/>
)
}
Binary file modified bun.lockb
Binary file not shown.
50 changes: 43 additions & 7 deletions lib/agents/engineer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Octokit} from '@octokit/core'
import {initializeAgentExecutorWithOptions} from 'langchain/agents'
import {ChatOpenAI} from 'langchain/chat_models/openai'
import env from '~/env.mjs'
import prisma from '~/prisma'
import {codebaseSearch} from '~/tools/codeSearch'
import commitCode from '~/tools/commitCode'
import listFiles from '~/tools/listFiles'
Expand All @@ -11,23 +12,41 @@ import writeFile from '~/tools/writeFile'
import {getInstallationId, getInstallationToken} from '~/utils/github'
import {isDev} from '~/utils/index'

const model = new ChatOpenAI({
modelName: 'gpt-4-1106-preview',
openAIApiKey: env.OPENAI_API_KEY,
temperature: 0.3
})

export async function engineer({
task,
repoFullName,
issueNumber,
customerId
customerId,
projectId
}: {
task: string
repoFullName: string
issueNumber: number
customerId: string
projectId: string
}) {
let tokens = {
prompt: 0,
completion: 0
}

const model = new ChatOpenAI({
modelName: 'gpt-4-1106-preview',
openAIApiKey: env.OPENAI_API_KEY,
temperature: 0.3,
callbacks: [
{
async handleLLMEnd(data) {
tokens = {
prompt: tokens.prompt + (data?.llmOutput?.tokenUsage?.promptTokens || 0),
completion:
tokens.completion + (data?.llmOutput?.tokenUsage?.completionTokens || 0)
}
}
}
]
})

const {content: title} = await model.call([
'Could you output a very concise PR title for this request?',
`Task: ${task}`
Expand Down Expand Up @@ -82,6 +101,23 @@ Your final output message should be the message that will be included in the pul
returnIntermediateSteps: isDev,
handleParsingErrors: true,
// verbose: true,
callbacks: [
{
async handleChainEnd() {
await prisma.usage.create({
data: {
projectId: projectId,
totalTokens: tokens.prompt + tokens.completion,
promptTokens: tokens.prompt,
completionTokens: tokens.completion,
action: 'Create some stuff with engineer',
agent: 'engineer',
model: 'gpt-4-1106-preview'
}
})
}
}
],
agentArgs: {
prefix
}
Expand Down
59 changes: 48 additions & 11 deletions lib/agents/maige.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {initializeAgentExecutorWithOptions} from 'langchain/agents'
import {ChatOpenAI} from 'langchain/chat_models/openai'
import env from '~/env.mjs'
import prisma from '~/prisma'
import {codebaseSearch} from '~/tools/codeSearch'
import commentTool from '~/tools/comment'
import dispatchEngineer from '~/tools/dispatchEngineer'
Expand All @@ -10,17 +11,11 @@ import {labelTool} from '~/tools/label'
import updateInstructionsTool from '~/tools/updateInstructions'
import {isDev} from '~/utils/index'

const model = new ChatOpenAI({
modelName: 'gpt-4-1106-preview',
openAIApiKey: env.OPENAI_API_KEY,
temperature: 0
})

export async function maige({
input,
octokit,
prisma,
customerId,
projectId,
repoFullName,
issueNumber,
issueId,
Expand All @@ -31,8 +26,8 @@ export async function maige({
}: {
input: string
octokit: any
prisma: any
customerId: string
projectId: string
repoFullName: string
issueNumber?: number
issueId?: string
Expand All @@ -41,6 +36,29 @@ export async function maige({
comment: any
beta?: boolean
}) {
let tokens = {
prompt: 0,
completion: 0
}

const model = new ChatOpenAI({
modelName: 'gpt-4-1106-preview',
openAIApiKey: env.OPENAI_API_KEY,
temperature: 0,
streaming: false,
callbacks: [
{
async handleLLMEnd(data) {
tokens = {
prompt: tokens.prompt + (data?.llmOutput?.tokenUsage?.promptTokens || 0),
completion:
tokens.completion + (data?.llmOutput?.tokenUsage?.completionTokens || 0)
}
}
}
]
})

const tools = [
labelTool({octokit, allLabels, issueId}),
updateInstructionsTool({
Expand All @@ -54,10 +72,12 @@ export async function maige({
}),
githubTool({octokit}),
codebaseSearch({customerId, repoFullName}),
...(beta ? [dispatchEngineer({issueNumber, repoFullName, customerId})] : []),
...(beta
? [dispatchEngineer({issueNumber, repoFullName, customerId, projectId})]
: []),
...(issueId ? [commentTool({octokit, issueId})] : []),
...(pullUrl && beta
? [dispatchReviewer({octokit, pullUrl, repoFullName, customerId})]
? [dispatchReviewer({octokit, pullUrl, repoFullName, customerId, projectId})]
: [])
]

Expand All @@ -84,7 +104,24 @@ All repo labels: ${allLabels
// verbose: true,
agentArgs: {
prefix
}
},
callbacks: [
{
async handleChainEnd() {
await prisma.usage.create({
data: {
projectId: projectId,
totalTokens: tokens.prompt + tokens.completion,
promptTokens: tokens.prompt,
completionTokens: tokens.completion,
action: 'Review an issue with maige',
agent: 'maige',
model: 'gpt-4-1106-preview'
}
})
}
}
]
})

const {output} = await executor.call({input})
Expand Down
Loading