Skip to content

Commit

Permalink
feat: improv analytics (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Jun 26, 2024
1 parent 3194b87 commit 400d815
Show file tree
Hide file tree
Showing 34 changed files with 534 additions and 2,211 deletions.
1,296 changes: 59 additions & 1,237 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
],
"dependencies": {
"concurrently": "^8.2.2",
"patch-package": "^8.0.0",
"react-markdown": "^9.0.1"
"patch-package": "^8.0.0"
},
"devDependencies": {
"@playwright/test": "^1.42.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/api/v1/analytics/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { convertChecksToSQL } from "@/src/utils/checks"
import sql from "@/src/utils/db"

import Context from "@/src/utils/koa"
import { deserializeLogic } from "shared"
import { z } from "zod"

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

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

export default v1
85 changes: 0 additions & 85 deletions packages/backend/src/api/v1/views.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/backend/src/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,13 @@ function postgresOperators(operator: string) {

export const CHECK_RUNNERS: CheckRunner[] = [
{
id: "fulltype",
id: "type",
sql: ({ type }) =>
type === "trace"
? // matches agent and chain runs with no parent or parent is a chat run
sql`(r.type in ('agent','chain') and (parent_run_id is null OR EXISTS (SELECT 1 FROM run AS parent_run WHERE parent_run.id = r.parent_run_id AND parent_run.type = 'chat')))`
: sql`(r.type = ${type})`,
},
{
id: "type",
sql: ({ type }) => sql`(r.type = ${type})`,
},
{
id: "models",
sql: ({ models }) => sql`(r.name = any(${models}))`,
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import { startMaterializedViewRefreshJob } from "./jobs/materializedViews"
checkDbConnection()
setupCronJobs()

startMaterializedViewRefreshJob()
if (process.env.NODE_ENV === "production") {
startMaterializedViewRefreshJob()
}
initSentry()

const app = new Koa()
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/jobs/materializedViews.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import sql from "../utils/db"
import { sleep } from "../utils/misc"

const REFRESH_FREQUENCY = process.env.NODE_ENV === "production" ? 1000 : 10000

export async function startMaterializedViewRefreshJob() {
try {
const views = [
Expand All @@ -23,7 +21,7 @@ export async function startMaterializedViewRefreshJob() {
)
}

await sleep(REFRESH_FREQUENCY)
await sleep(1000)
}
} catch (error) {
console.error(error)
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/utils/calcCost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ const MODEL_COSTS: ModelCost[] = [
inputCost: 0.008,
outputCost: 0.024,
},
{
models: ["claude-3.5-sonnet"],
inputCost: 0.003,
outputCost: 0.015,
},
{
models: ["claude-3-opus"],
inputCost: 0.015,
outputCost: 0.075,
},
{
models: ["claude-3-5-sonnet"],
inputCost: 0.003,
outputCost: 0.075,
},
{
models: ["claude-3-sonnet"],
inputCost: 0.003,
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/utils/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ export const ingestChatEvent = async (
metadata: metadata || extra,
})

console.log({ coreMessage })

if (typeof parentRunId === "undefined") {
throw new Error("parentRunId is undefined")
}
Expand Down
13 changes: 0 additions & 13 deletions packages/db/0022.sql

This file was deleted.

5 changes: 2 additions & 3 deletions packages/frontend/components/SmartViewer/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
TextInput,
Textarea,
ThemeIcon,
useComputedColorScheme,
} from "@mantine/core"
import {
IconInfoCircle,
Expand All @@ -27,6 +26,7 @@ import Image from "next/image"
import ProtectedText from "../blocks/ProtectedText"
import { RenderJson } from "./RenderJson"

import { useColorScheme } from "@mantine/hooks"
import { circularPro } from "@/utils/theme"
import { useEffect } from "react"

Expand Down Expand Up @@ -441,8 +441,7 @@ export function ChatMessage({
}) {
// TODO FIX
// Flickering dark mode bug: this is due to scheme being 'light' for a few ms

const scheme = useComputedColorScheme()
const scheme = useColorScheme()

const color = getColorForRole(data?.role)

Expand Down
15 changes: 4 additions & 11 deletions packages/frontend/components/analytics/BarList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
Flex,
Progress,
Table,
Text,
Tooltip,
useComputedColorScheme,
} from "@mantine/core"
import { Flex, Progress, Table, Text, Tooltip } from "@mantine/core"
import { useColorScheme } from "@mantine/hooks"

type BarListProps = {
data: any[]
Expand All @@ -25,8 +19,7 @@ function BarList({ data, columns, filterZero = true }: BarListProps) {
const dataColumns = columns.filter((col) => !col.bar && col.key)
const main = dataColumns.find((col) => col.main) || dataColumns[0]
const mainTotal = data.reduce((acc, item) => acc + (item[main.key] || 0), 0)

const colorScheme = useComputedColorScheme()
const scheme = useColorScheme()

if (!data) return <>No data.</>

Expand Down Expand Up @@ -91,7 +84,7 @@ function BarList({ data, columns, filterZero = true }: BarListProps) {
justify="center"
>
<Text
c={colorScheme === "dark" ? "white" : "dark"}
c={scheme === "dark" ? "white" : "dark"}
mb={-3}
size="12px"
style={{
Expand Down
Loading

0 comments on commit 400d815

Please sign in to comment.