Skip to content

Commit

Permalink
[1/2] delete label type field
Browse files Browse the repository at this point in the history
  • Loading branch information
dinmukhamedm committed Jan 18, 2025
1 parent 3aed491 commit 2ccdc1c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 35 deletions.
12 changes: 0 additions & 12 deletions app-server/src/db/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ use serde_json::Value;
use sqlx::{FromRow, PgPool, QueryBuilder};
use uuid::Uuid;

#[derive(sqlx::Type, Deserialize, Serialize, Debug, Clone, PartialEq)]
#[sqlx(type_name = "label_type")]
pub enum LabelType {
BOOLEAN,
CATEGORICAL,
}

#[derive(sqlx::Type, Serialize, Deserialize, Clone, PartialEq)]
#[sqlx(type_name = "label_source")]
pub enum LabelSource {
Expand All @@ -27,7 +20,6 @@ pub struct LabelClass {
pub created_at: DateTime<Utc>,
pub name: String,
pub project_id: Uuid,
pub label_type: LabelType,
pub value_map: Value, // HashMap<String, f64>
pub description: Option<String>,
pub evaluator_runnable_graph: Option<Value>,
Expand Down Expand Up @@ -59,7 +51,6 @@ pub struct SpanLabel {
pub label_source: LabelSource,
pub reasoning: Option<String>,

pub label_type: LabelType,
pub class_name: String,
pub value_map: Value, // Vec<Value>
pub description: Option<String>,
Expand Down Expand Up @@ -90,7 +81,6 @@ pub async fn get_label_classes_by_project_id(
created_at,
name,
project_id,
label_type,
value_map,
description,
evaluator_runnable_graph
Expand Down Expand Up @@ -141,7 +131,6 @@ pub async fn update_label_class(
created_at,
name,
project_id,
label_type,
value_map,
description,
evaluator_runnable_graph",
Expand Down Expand Up @@ -237,7 +226,6 @@ pub async fn get_span_labels(pool: &PgPool, span_id: Uuid) -> Result<Vec<SpanLab
labels.label_source,
labels.reasoning,
users.email as user_email,
label_classes.label_type,
label_classes.value_map,
label_classes.name as class_name,
label_classes.description
Expand Down
2 changes: 1 addition & 1 deletion app-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ fn main() -> anyhow::Result<()> {
.service(routes::traces::get_single_trace)
.service(routes::traces::get_single_span)
.service(routes::traces::get_sessions)
.service(routes::labels::get_label_types)
.service(routes::labels::get_label_classes)
.service(routes::labels::get_span_labels)
.service(routes::labels::update_span_label)
.service(routes::labels::delete_span_label)
Expand Down
2 changes: 1 addition & 1 deletion app-server/src/routes/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::db::{self, labels::LabelSource, user::User, DB};
use super::ResponseResult;

#[get("label-classes")]
pub async fn get_label_types(path: web::Path<Uuid>, db: web::Data<DB>) -> ResponseResult {
pub async fn get_label_classes(path: web::Path<Uuid>, db: web::Data<DB>) -> ResponseResult {
let project_id = path.into_inner();
let label_classes =
db::labels::get_label_classes_by_project_id(&db.pool, project_id, None).await?;
Expand Down
4 changes: 1 addition & 3 deletions frontend/app/api/projects/[projectId]/label-classes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ export async function POST(req: Request, props: { params: Promise<{ projectId: s
const params = await props.params;
const projectId = params.projectId;



const body = await req.json();

const res = await db.insert(labelClasses).values({
projectId: projectId,
name: body.name,
labelType: "CATEGORICAL",
description: body.description,
labelType: body.labelType,
evaluatorRunnableGraph: body.evaluatorRunnableGraph,
valueMap: body.valueMap
}).returning();
Expand Down
7 changes: 2 additions & 5 deletions frontend/components/traces/add-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ArrowLeft, HelpCircle, Loader2, Trash2 } from 'lucide-react';
import { useState } from 'react';

import { useProjectContext } from '@/contexts/project-context';
import { LabelClass, LabelType, Span } from '@/lib/traces/types';
import { LabelClass, Span } from '@/lib/traces/types';

import { EvaluatorEditorDialog } from '../evaluator/evaluator-editor-dialog';
import { Button } from '../ui/button';
Expand All @@ -24,18 +24,15 @@ interface AddLabelProps {

export function AddLabel({ span, onClose }: AddLabelProps) {
const { projectId } = useProjectContext();
const [selectedType, setSelectedType] = useState<LabelType>(
LabelType.BOOLEAN
);
const [isSaving, setIsSaving] = useState(false);
const [showEvaluator, setShowEvaluator] = useState(false);

const [labelClass, setLabelClass] = useState<LabelClass>({
id: '',
name: '',
projectId: projectId,
labelType: 'CATEGORICAL',
createdAt: '',
labelType: LabelType.CATEGORICAL,
valueMap: {
"False": 0,
"True": 1
Expand Down
16 changes: 8 additions & 8 deletions frontend/lib/db/migrations/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sql } from "drizzle-orm";
import { bigint, boolean, doublePrecision, foreignKey, index, integer, jsonb, pgEnum,pgPolicy, pgTable, primaryKey, text, timestamp, unique, uuid } from "drizzle-orm/pg-core";
import { bigint, boolean, doublePrecision, foreignKey, index, integer, jsonb, pgEnum, pgPolicy, pgTable, primaryKey, text, timestamp, unique, uuid } from "drizzle-orm/pg-core";

export const labelSource = pgEnum("label_source", ['MANUAL', 'AUTO', 'CODE']);
export const labelType = pgEnum("label_type", ['BOOLEAN', 'CATEGORICAL']);
Expand Down Expand Up @@ -34,7 +34,7 @@ export const apiKeys = pgTable("api_keys", {
foreignColumns: [users.id],
name: "api_keys_user_id_fkey"
}).onUpdate("cascade").onDelete("cascade"),
enableInsertForAuthenticatedUsersOnly: pgPolicy("Enable insert for authenticated users only", { as: "permissive", for: "all", to: ["service_role"], using: sql`true`, withCheck: sql`true` }),
enableInsertForAuthenticatedUsersOnly: pgPolicy("Enable insert for authenticated users only", { as: "permissive", for: "all", to: ["service_role"], using: sql`true`, withCheck: sql`true` }),
}));

export const labelClasses = pgTable("label_classes", {
Expand All @@ -43,7 +43,7 @@ export const labelClasses = pgTable("label_classes", {
name: text().notNull(),
projectId: uuid("project_id").notNull(),
labelType: labelType("label_type").notNull(),
valueMap: jsonb("value_map").default([false,true]).notNull(),
valueMap: jsonb("value_map").default([false, true]).notNull(),
description: text(),
evaluatorRunnableGraph: jsonb("evaluator_runnable_graph"),
pipelineVersionId: uuid("pipeline_version_id"),
Expand Down Expand Up @@ -296,15 +296,15 @@ export const users = pgTable("users", {
email: text().notNull(),
}, (table) => ({
usersEmailKey: unique("users_email_key").on(table.email),
enableInsertForAuthenticatedUsersOnly: pgPolicy("Enable insert for authenticated users only", { as: "permissive", for: "insert", to: ["service_role"], withCheck: sql`true` }),
enableInsertForAuthenticatedUsersOnly: pgPolicy("Enable insert for authenticated users only", { as: "permissive", for: "insert", to: ["service_role"], withCheck: sql`true` }),
}));

export const playgrounds = pgTable("playgrounds", {
id: uuid().defaultRandom().primaryKey().notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(),
name: text().notNull(),
projectId: uuid("project_id").notNull(),
promptMessages: jsonb("prompt_messages").default([{"role":"user","content":""}]).notNull(),
promptMessages: jsonb("prompt_messages").default([{ "role": "user", "content": "" }]).notNull(),
modelId: text("model_id").default('').notNull(),
outputSchema: text("output_schema"),
}, (table) => ({
Expand Down Expand Up @@ -503,7 +503,7 @@ export const machines = pgTable("machines", {
foreignColumns: [projects.id],
name: "machines_project_id_fkey"
}).onUpdate("cascade").onDelete("cascade"),
machinesPkey: primaryKey({ columns: [table.id, table.projectId], name: "machines_pkey"}),
machinesPkey: primaryKey({ columns: [table.id, table.projectId], name: "machines_pkey" }),
}));

export const datapointToSpan = pgTable("datapoint_to_span", {
Expand All @@ -522,7 +522,7 @@ export const datapointToSpan = pgTable("datapoint_to_span", {
foreignColumns: [spans.spanId, spans.projectId],
name: "datapoint_to_span_span_id_project_id_fkey"
}).onUpdate("cascade").onDelete("cascade"),
datapointToSpanPkey: primaryKey({ columns: [table.datapointId, table.spanId, table.projectId], name: "datapoint_to_span_pkey"}),
datapointToSpanPkey: primaryKey({ columns: [table.datapointId, table.spanId, table.projectId], name: "datapoint_to_span_pkey" }),
}));

export const spans = pgTable("spans", {
Expand Down Expand Up @@ -558,6 +558,6 @@ export const spans = pgTable("spans", {
foreignColumns: [projects.id],
name: "spans_project_id_fkey"
}).onUpdate("cascade"),
spansPkey: primaryKey({ columns: [table.spanId, table.projectId], name: "spans_pkey"}),
spansPkey: primaryKey({ columns: [table.spanId, table.projectId], name: "spans_pkey" }),
uniqueSpanIdProjectId: unique("unique_span_id_project_id").on(table.spanId, table.projectId),
}));
5 changes: 0 additions & 5 deletions frontend/lib/traces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { GraphMessagePreview } from '../pipeline/types';

export type TraceMessages = { [key: string]: GraphMessagePreview };

export enum LabelType {
CATEGORICAL = 'CATEGORICAL',
BOOLEAN = 'BOOLEAN'
}

export enum LabelSource {
AUTO = 'AUTO',
MANUAL = 'MANUAL'
Expand Down

0 comments on commit 2ccdc1c

Please sign in to comment.