diff --git a/packages/backend/src/api/v1/runs/index.ts b/packages/backend/src/api/v1/runs/index.ts index 41dcc28a..6cd306dc 100644 --- a/packages/backend/src/api/v1/runs/index.ts +++ b/packages/backend/src/api/v1/runs/index.ts @@ -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"; @@ -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 @@ -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; diff --git a/packages/python-sdk/lunary/__init__.py b/packages/python-sdk/lunary/__init__.py index 8eb6f219..e85c10f6 100644 --- a/packages/python-sdk/lunary/__init__.py +++ b/packages/python-sdk/lunary/__init__.py @@ -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. diff --git a/packages/python-sdk/pyproject.toml b/packages/python-sdk/pyproject.toml index b0edb30f..b81de9dd 100644 --- a/packages/python-sdk/pyproject.toml +++ b/packages/python-sdk/pyproject.toml @@ -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 "] readme = "README.md"