Skip to content

Commit

Permalink
fix evals
Browse files Browse the repository at this point in the history
  • Loading branch information
vincelwt committed Apr 30, 2024
1 parent d861e1b commit f8c24c7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"p-queue": "^8.0.1",
"postgres": "^3.4.3",
"prexit": "^2.2.0",
"queue-promise": "^2.2.1",
"rouge": "^1.0.3",
"samlify": "^2.8.11",
"shared": "*",
Expand Down
37 changes: 23 additions & 14 deletions packages/backend/src/api/v1/evaluations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import sql from "@/src/utils/db"
import Context from "@/src/utils/koa"
import Router from "koa-router"
import { RunEvent } from "lunary/types"
import PQueue from "p-queue"

import Queue from "queue-promise"
import { PassThrough } from "stream"
import { runEval } from "./utils"

Expand All @@ -31,9 +32,9 @@ evaluations.post(
Connection: "keep-alive",
})

const queue = new PQueue({
concurrency: MAX_PARALLEL_EVALS,
timeout: 10000,
const queue = new Queue({
concurrent: MAX_PARALLEL_EVALS,
start: true,
})

const [{ plan }] =
Expand Down Expand Up @@ -70,16 +71,17 @@ evaluations.post(
for (const variation of variations) {
for (const provider of evaluation.providers) {
count++
queue.add(() =>
runEval({
queue.enqueue(async () => {
await runEval({
evaluationId: evaluation.id,
promptId: prompt.id,
variation,
provider,
prompt: prompt.messages,
checklistId,
}),
)
})
console.log(`Task ${count} don with model ${provider.model} done`)
})
}
}
}
Expand All @@ -89,17 +91,24 @@ evaluations.post(
ctx.status = 200
ctx.body = stream

queue.on("active", () => {
const percentDone = ((count - queue.size) / count) * 100
console.log(`Active: ${queue.size} of ${count} (${percentDone}%)`)
let done = 0

queue.on("dequeue", () => {
done++
const percentDone = (1 - (count - done) / count) * 100
console.log(`Active: ${done} of ${count} (${percentDone}%)`)
stream.write(JSON.stringify({ percentDone }) + "\n")
})

await queue.onIdle()
console.log(`Queue started with ${count} tasks`)

stream.write(JSON.stringify({ id: evaluation?.id }) + "\n")
queue.on("end", () => {
console.log("Queue is empty now")

stream.end()
stream.write(JSON.stringify({ id: evaluation?.id }) + "\n")

stream.end()
})
},
)

Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/api/v1/evaluations/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export async function runEval({
duration,
})}
`

console.log(`Eval for ${provider.model} passed: ${passed}`)
} catch (error: any) {
await sql`
insert into evaluation_result ${sql({
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/utils/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ async function licenseMiddleware(ctx: Context, next: Next) {

try {
if (Date.now() - cache.lastFetch > TWO_HOURS) {
console.log("Fetching")
const licenseData = await fetch(
`https://license.lunary.ai/v1/licenses/${LICENSE_KEY}`,
).then((res) => res.json())
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/components/evals/ResultsMatrix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function ResultCell({ result }) {
<>
{result.status === "success" ? (
<Stack align="center" justify="between">
<ChatMessage data={result.output} mah={150} compact w="100%" />
<ChatMessage data={result.output} mah={300} compact w="100%" />

<HoverCard width={500} disabled={!result.results.length}>
<HoverCard.Target>
Expand Down

0 comments on commit f8c24c7

Please sign in to comment.