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

feat: revamp UX #411

Merged
merged 90 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
52ccabd
fix: unclickable menu items
vincelwt Jun 25, 2024
5e65ce6
move to hooks
vincelwt Jun 26, 2024
43a3ab0
revamp navbar
vincelwt Jul 6, 2024
ce0a744
save
vincelwt Jul 7, 2024
2d142cb
save
vincelwt Jul 7, 2024
723206a
add initial model migration
vincelwt Jul 7, 2024
1245fd0
save
vincelwt Jul 7, 2024
6a2e350
save
vincelwt Jul 7, 2024
584731f
save
vincelwt Jul 7, 2024
a619599
fix cost tracking
vincelwt Jul 8, 2024
7e0de37
upgrade package
vincelwt Jul 8, 2024
e85b28a
Merge branch 'main' into fix/navigation
vincelwt Jul 8, 2024
c5b3a63
Fix merge
vincelwt Jul 8, 2024
3793370
save
vincelwt Jul 8, 2024
5096395
icon picker
vincelwt Jul 8, 2024
da71e90
more icons
vincelwt Jul 8, 2024
b413138
improve perfs
vincelwt Jul 9, 2024
6fe6006
more perf
vincelwt Jul 9, 2024
2d4656c
save
vincelwt Jul 9, 2024
54132f5
fix table
vincelwt Jul 9, 2024
0aa664b
improve UI
vincelwt Jul 9, 2024
35afe97
improve table
vincelwt Jul 9, 2024
fd4d454
initial commit
hughcrt Jul 9, 2024
f619e8c
fix selector
vincelwt Jul 9, 2024
4063647
add missing
vincelwt Jul 9, 2024
cfbaef8
add field for custom regex
vincelwt Jul 9, 2024
4e038cb
geval soon
vincelwt Jul 9, 2024
293b7ce
update field names
vincelwt Jul 9, 2024
0818b1b
improve UI
vincelwt Jul 9, 2024
ae79290
fix query params
vincelwt Jul 9, 2024
4479d59
pii
hughcrt Jul 9, 2024
0b78c50
fix
hughcrt Jul 9, 2024
13c9e34
Merge branch 'feat/improve-eval-perf' into fix/navigation-v2
vincelwt Jul 9, 2024
a9f6112
save
vincelwt Jul 9, 2024
4829c81
add excluded entities
vincelwt Jul 9, 2024
b86243d
fix
vincelwt Jul 9, 2024
1547f4f
fix
vincelwt Jul 9, 2024
1fd5d26
clean
vincelwt Jul 9, 2024
acb6e65
Merge branch 'fix/navigation-v2' into feat/improve-eval-perf
vincelwt Jul 9, 2024
01b087d
update
hughcrt Jul 9, 2024
84a81a5
add feedback filter
vincelwt Jul 9, 2024
efc9282
Merge branch 'feat/improve-eval-perf' of github.com:lunary-ai/lunary …
vincelwt Jul 9, 2024
695234d
fix
vincelwt Jul 9, 2024
8635ede
fix
vincelwt Jul 9, 2024
c75777f
pii badge
vincelwt Jul 9, 2024
5b4317f
push
vincelwt Jul 9, 2024
527922f
don't show uniques
vincelwt Jul 9, 2024
c6fb719
tooltip
vincelwt Jul 9, 2024
6b4e791
clean
vincelwt Jul 9, 2024
eea43cc
add PII filter
vincelwt Jul 9, 2024
91f5fd2
filter
vincelwt Jul 9, 2024
05e7217
feat: sentiment
hughcrt Jul 9, 2024
2f244de
remove log
hughcrt Jul 9, 2024
6bce9bb
push
vincelwt Jul 9, 2024
389b342
Merge branch 'feat/improve-eval-perf' of github.com:lunary-ai/lunary …
vincelwt Jul 9, 2024
5fa3f4b
improve
vincelwt Jul 9, 2024
44b2149
fix style
vincelwt Jul 9, 2024
89694fe
feat: render sentiment
hughcrt Jul 10, 2024
7a20ebe
save
hughcrt Jul 10, 2024
3c5f869
Merge branch 'feat/improve-eval-perf' of github.com:lunary-ai/lunary …
hughcrt Jul 10, 2024
f670c7d
clean ui
vincelwt Jul 10, 2024
ca6b984
fix click
vincelwt Jul 10, 2024
6cd12da
Merge branch 'feat/improve-eval-perf' of github.com:lunary-ai/lunary …
vincelwt Jul 10, 2024
dc2e4fe
update
hughcrt Jul 10, 2024
9489e1a
filter
vincelwt Jul 10, 2024
56f8f10
Merge branch 'feat/improve-eval-perf' of github.com:lunary-ai/lunary …
vincelwt Jul 10, 2024
45e3068
put back sleep
hughcrt Jul 10, 2024
6fb01bf
Merge branch 'main' into fix/navigation
vincelwt Jul 11, 2024
259f87a
Merge branch 'feat/improve-eval-perf' of github.com:lunary-ai/lunary …
vincelwt Jul 11, 2024
a3b1ac9
fix rendering enrichment
hughcrt Jul 12, 2024
725ffc1
feat: add proper exit code to allow restart by process manager
hughcrt Jul 15, 2024
ce27757
fix build
vincelwt Jul 15, 2024
7da7ab1
add search
vincelwt Jul 15, 2024
2babd33
make charts faster
vincelwt Jul 15, 2024
bbde67f
improve
vincelwt Jul 15, 2024
aac8e63
clean
vincelwt Jul 15, 2024
1c67d8c
fix
vincelwt Jul 15, 2024
f73a221
improve filters
vincelwt Jul 15, 2024
71da694
ok
hughcrt Jul 15, 2024
9ffb4ad
save
hughcrt Jul 15, 2024
322075a
fix API format
vincelwt Jul 15, 2024
60e9be6
Merge branch 'feat/improve-eval-perf' of github.com:lunary-ai/lunary …
vincelwt Jul 15, 2024
9b027c0
fix
vincelwt Jul 15, 2024
4b1c64e
clean
vincelwt Jul 15, 2024
1bf42d4
finished?
hughcrt Jul 15, 2024
3ff05f6
tests
hughcrt Jul 15, 2024
ee72e4d
ui fix
hughcrt Jul 15, 2024
d65d972
ok
hughcrt Jul 15, 2024
11e2a72
tests
hughcrt Jul 15, 2024
2c3827b
tests
hughcrt Jul 15, 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
5,517 changes: 3,848 additions & 1,669 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"start": "npm run migrate:db && tsx src/index.ts",
"start:radar": "tsx src/radar.ts",
"dev:realtime-evaluators": "tsx --env-file=.env --watch src/realtime-evaluators.ts",
"migrate:db": "tsx src/migrate.ts",
"build": "tsup src/index.ts --format esm",
"dev": "tsx --env-file=.env --watch src/index.ts",
Expand All @@ -13,15 +14,16 @@
},
"dependencies": {
"@authenio/samlify-node-xmllint": "^2.0.0",
"@aws-sdk/client-comprehend": "^3.609.0",
"@json2csv/plainjs": "^7.0.5",
"@koa/cors": "^5.0.0",
"@sentry/node": "^7.99.0",
"@sentry/profiling-node": "^1.3.5",
"@sentry/utils": "^7.99.0",
"@sentry/node": "^8.15.0",
"@sentry/profiling-node": "^8.15.0",
"@sentry/utils": "^8.15.0",
"@xenova/transformers": "^2.14.2",
"argon2": "^0.31.2",
"argon2": "^0.40.3",
"bcrypt": "^5.1.1",
"jose": "^5.2.0",
"jose": "^5.6.3",
"js-tiktoken": "1.0.7",
"jsonrepair": "^3.7.0",
"koa": "^2.15.3",
Expand All @@ -39,7 +41,7 @@
"rouge": "^1.0.3",
"samlify": "^2.8.11",
"shared": "*",
"stripe": "^15.5.0",
"stripe": "^16.2.0",
"washyourmouthoutwithsoap": "^1.0.2",
"zod": "^3.23.6"
},
Expand Down
26 changes: 12 additions & 14 deletions packages/backend/src/api/v1/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ analytics.get(
order by
date;
`
ctx.body = res
ctx.body = { data: res }
return
} else {
const res = await sql`
Expand All @@ -76,7 +76,7 @@ analytics.get(
order by d.date;
`

ctx.body = res
ctx.body = { data: res }
return
}
},
Expand Down Expand Up @@ -122,7 +122,7 @@ analytics.get(
order by
date;
`
ctx.body = res
ctx.body = { data: res }
return
} else {
const res = await sql`
Expand All @@ -145,7 +145,7 @@ analytics.get(
order by d.date;
`

ctx.body = res
ctx.body = { data: res }
return
}
},
Expand Down Expand Up @@ -191,7 +191,7 @@ analytics.get(
order by
date;
`
ctx.body = res
ctx.body = { data: res }
return
} else {
const res = await sql`
Expand All @@ -213,7 +213,7 @@ analytics.get(
order by d.date;
`

ctx.body = res
ctx.body = { data: res }
return
}
},
Expand Down Expand Up @@ -272,7 +272,7 @@ analytics.get(
date

`
ctx.body = res
ctx.body = { data: res }
return
} else {
const res = await sql`
Expand All @@ -299,7 +299,7 @@ analytics.get(
order by
d.date;
`
ctx.body = res
ctx.body = { data: res }
return
}
},
Expand Down Expand Up @@ -572,7 +572,7 @@ analytics.get(
order by
date;
`
ctx.body = res
ctx.body = { data: res }
return
} else {
const res = await sql`
Expand All @@ -595,7 +595,7 @@ analytics.get(
order by d.date;
`

ctx.body = res
ctx.body = { data: res }
return
}
},
Expand Down Expand Up @@ -741,7 +741,7 @@ analytics.get(
order by
date;
`
ctx.body = res
ctx.body = { data: res }
return
} else {
const res = await sql`
Expand Down Expand Up @@ -776,7 +776,7 @@ analytics.get(
order by
d.date;
`
ctx.body = res
ctx.body = { data: res }
return
}
},
Expand Down Expand Up @@ -840,8 +840,6 @@ analytics.get(
limit 5
`

console.log(topModels)

ctx.body = topModels
},
)
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/api/v1/evaluations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ evaluations.post(
count++
queue.enqueue(async () => {
await runEval({
projectId,
evaluationId: evaluation.id,
promptId: prompt.id,
variation,
Expand Down Expand Up @@ -219,7 +220,7 @@ evaluations.post(
cost: 0,
}

const cost = calcRunCost(virtualRun)
const cost = await calcRunCost(virtualRun)
virtualRun.cost = cost
virtualRun.duration = virtualRun.duration / 1000 // needs to be in ms in calcRunCost, but needs to be in seconds in the checks

Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/api/v1/evaluations/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { compilePrompt, runAImodel } from "@/src/utils/playground"
import { Provider } from "shared"

interface RunEvalParams {
projectId: string
evaluationId: string
promptId: string
checklistId: string
Expand All @@ -15,6 +16,7 @@ interface RunEvalParams {
}

export async function runEval({
projectId,
evaluationId,
promptId,
checklistId,
Expand Down Expand Up @@ -92,12 +94,12 @@ export async function runEval({
idealOutput,
// So the SQL queries don't fail:
id: "00000000-0000-4000-8000-000000000000",
projectId: "00000000-0000-4000-8000-000000000000",
projectId,
isPublic: false,
cost: 0,
}

const cost = calcRunCost(virtualRun)
const cost = await calcRunCost(virtualRun)
virtualRun.cost = cost || 0
virtualRun.duration = virtualRun.duration / 1000 // needs to be in ms in calcRunCost, but needs to be in seconds in the checks

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/api/v1/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ evaluators.get("/:id", async (ctx: Context) => {
})

evaluators.post("/", async (ctx: Context) => {
console.log(ctx.request.body)
const requestBody = z.object({
ownerId: z.string().optional(),
name: z.string(),
Expand Down
73 changes: 43 additions & 30 deletions packages/backend/src/api/v1/external-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,52 @@ users.get("/", checkAccess("users", "list"), async (ctx: Context) => {
`
}

const users = await sql`
with user_costs as (
const [users, total] = await Promise.all([
sql`
with user_costs as (
select
external_user_id,
coalesce(sum(cost), 0) as cost
from
run r
where
project_id = ${projectId}
${createAtQuery}
group by
external_user_id
)
select
external_user_id,
coalesce(sum(cost), 0) as cost
eu.id,
eu.created_at,
eu.external_id,
eu.last_seen,
eu.props,
uc.cost
from
run r
public.external_user eu
left join user_costs uc on eu.id = uc.external_user_id
where
project_id = ${projectId}
${createAtQuery}
group by
external_user_id
)
select
eu.id,
eu.created_at,
eu.external_id,
eu.last_seen,
eu.props,
uc.cost
from
public.external_user eu
left join user_costs uc on eu.id = uc.external_user_id
where
eu.project_id = ${projectId}
${searchQuery}
order by
cost desc nulls last
limit ${limit}
offset ${page * limit}
`

ctx.body = users
eu.project_id = ${projectId}
${searchQuery}
order by
cost desc nulls last
limit ${limit}
offset ${page * limit}
`,
sql`
select count(*) as total
from public.external_user eu
where eu.project_id = ${projectId}
${searchQuery}
`,
])

ctx.body = {
total: +total[0].total,
page,
limit,
data: users,
}
})

// TODO: deprecated?
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/api/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import templates from "./templates"
import users from "./users"
import evaluators from "./evaluator"
import analytics from "./analytics"
import views from "./views"
import models from "./models"

const v1 = new Router({
prefix: "/v1",
Expand Down Expand Up @@ -48,5 +50,7 @@ v1.use(evaluations.routes())
v1.use(projectUsers.routes())
v1.use(checklists.routes())
v1.use(analytics.routes())
v1.use(views.routes())
v1.use(models.routes())

export default v1
77 changes: 77 additions & 0 deletions packages/backend/src/api/v1/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { checkAccess } from "@/src/utils/authorization"
import sql from "@/src/utils/db"
import { clearUndefined } from "@/src/utils/ingest"
import Context from "@/src/utils/koa"
import Router from "koa-router"
import { z } from "zod"

const models = new Router({
prefix: "/models",
})

const ModelSchema = z.object({
name: z.string().min(1),
pattern: z.string().min(1),
unit: z.enum(["TOKENS", "CHARACTERS", "MILLISECONDS"]),
inputCost: z.number().min(0),
outputCost: z.number().min(0),
tokenizer: z.string().optional(),
startDate: z.coerce.date().optional(),
})

models.get("/", checkAccess("logs", "list"), async (ctx: Context) => {
const { orgId } = ctx.state

ctx.body = await sql`select * from model_mapping
where org_id = ${orgId} or org_id is null
order by updated_at desc`
})

models.post("/", async (ctx: Context) => {
const { orgId } = ctx.state

const validatedData = ModelSchema.parse(ctx.request.body)

const [insertedModel] = await sql`
insert into model_mapping ${sql(
clearUndefined({
...validatedData,
orgId,
}),
)}
returning *
`
ctx.body = insertedModel
})

models.patch("/:id", async (ctx: Context) => {
const { orgId } = ctx.state
const { id } = ctx.params

const validatedData = ModelSchema.partial().parse(ctx.request.body)

const [updatedModel] = await sql`
update model_mapping
set ${sql(clearUndefined({ ...validatedData, updatedAt: new Date() }))}
where org_id = ${orgId}
and id = ${id}
returning *
`
ctx.body = updatedModel
})

models.delete("/:id", checkAccess("logs", "delete"), async (ctx: Context) => {
const { orgId } = ctx.state
const { id } = ctx.params

await sql`
delete from model_mapping
where org_id = ${orgId}
and id = ${id}
returning *
`

ctx.status = 200
})

export default models
Loading
Loading