Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: scores #729

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 12 additions & 15 deletions packages/backend/src/api/v1/runs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sql from "@/src/utils/db";
import Router from "koa-router";

import { checkAccess, checkProjectAccess } from "@/src/utils/authorization";
import { checkAccess } from "@/src/utils/authorization";
import { convertChecksToSQL } from "@/src/utils/checks";
import { jsonrepair } from "jsonrepair";
import { Feedback, Score, deserializeLogic } from "shared";
Expand Down Expand Up @@ -830,13 +830,16 @@ runs.get("/:id", async (ctx) => {
'updatedAt', er.updated_at
)
) filter (where er.run_id is not null), '{}') as evaluation_results,
coalesce(array_agg(
json_build_object(
'label', rs.label,
'value', rs.value,
'comment', rs.comment
)
) filter (where rs.run_id is not null), '{}') as scores
coalesce(
jsonb_agg(
distinct jsonb_build_object(
'value', rs.value,
'label', rs.label,
'comment', rs.comment
)
) filter (where rs.run_id is not null),
'[]'::jsonb
) as scores
from
run r
left join run_score rs on r.id = rs.run_id
Expand Down Expand Up @@ -1046,21 +1049,15 @@ runs.patch(
checkAccess("logs", "update"),
async (ctx: Context) => {
const { id: runId } = ctx.params;
const { projectId, userId } = ctx.state;
const { label, value, comment } = Score.parse(ctx.request.body);

const hasProjectAccess = await checkProjectAccess(projectId, userId);
if (!hasProjectAccess) {
ctx.throw(401, "Unauthorized");
}

let [existingScore] =
await sql`select * from run_score where run_id = ${runId} and label = ${label}`;

if (!existingScore) {
await sql`insert into run_score ${sql({ runId, label, value, comment })}`;
} else {
await sql`update run_score set ${sql({ label, value, comment })} where run_id = ${runId}`;
await sql`update run_score set ${sql({ label, value, comment })} where run_id = ${runId} and label = ${label}`;
}

ctx.status = 200;
Expand Down
2 changes: 1 addition & 1 deletion packages/python-sdk/lunary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ def get_dataset(slug: str, app_id: str | None = None, api_url: str | None = None
except Exception as e:
raise DatasetError(f"Error fetching dataset: {str(e)}")

def score(run_id: str, label: str, value: int | float | str | bool, comment: str | None, app_id: str | None = None, api_url: str | None = None):
def score(run_id: str, label: str, value: int | float | str | bool, comment: str | None = None, app_id: str | None = None, api_url: str | None = None):
"""
Scores a run based on the provided label, value, and optional comment.

Expand Down
2 changes: 1 addition & 1 deletion packages/python-sdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lunary"
version = "1.4.4"
version = "1.4.5"
description = "Observability, analytics and evaluations for AI agents and chatbots."
authors = ["lunary <hello@lunary.ai>"]
readme = "README.md"
Expand Down
Loading