From 0687d76e8e22878f5ccb87cec6c9949d0e38033e Mon Sep 17 00:00:00 2001 From: Max Deichmann Date: Mon, 11 Dec 2023 21:31:53 +0100 Subject: [PATCH] stuff --- langfuse-core/src/index.ts | 10 +-- langfuse-core/src/types.ts | 122 +++++++++++++++++++++++++++---------- 2 files changed, 94 insertions(+), 38 deletions(-) diff --git a/langfuse-core/src/index.ts b/langfuse-core/src/index.ts index 5b7b3cd0..f02cac56 100644 --- a/langfuse-core/src/index.ts +++ b/langfuse-core/src/index.ts @@ -151,7 +151,7 @@ abstract class LangfuseCoreStateless { const parsedBody: CreateLangfuseEventBody = { id, - startTime: bodyStartTime ?? new Date(), + startTime: bodyStartTime ?? currentISOTime(), ...rest, }; this.enqueue("observation-create", parsedBody); @@ -165,7 +165,7 @@ abstract class LangfuseCoreStateless { const parsedBody: CreateLangfuseSpanBody = { id, - startTime: bodyStartTime ?? new Date(), + startTime: bodyStartTime ?? currentISOTime(), ...rest, }; this.enqueue("observation-create", parsedBody); @@ -179,7 +179,7 @@ abstract class LangfuseCoreStateless { const parsedBody: CreateLangfuseGenerationBody = { id, - startTime: bodyStartTime ?? new Date(), + startTime: bodyStartTime ?? currentISOTime(), ...rest, }; this.enqueue("observation-create", parsedBody); @@ -667,7 +667,7 @@ export class LangfuseSpanClient extends LangfuseObservationClient { ...body, spanId: this.id, traceId: this.traceId, - endTime: new Date(), + endTime: currentISOTime(), }); return this; } @@ -692,7 +692,7 @@ export class LangfuseGenerationClient extends LangfuseObservationClient { ...body, generationId: this.id, traceId: this.traceId, - endTime: new Date(), + endTime: currentISOTime(), }); return this; } diff --git a/langfuse-core/src/types.ts b/langfuse-core/src/types.ts index 666d94c2..dbcc4a9c 100644 --- a/langfuse-core/src/types.ts +++ b/langfuse-core/src/types.ts @@ -1,4 +1,4 @@ -import { type paths } from "./openapi/server"; +import { type components, type paths } from "./openapi/server"; export type LangfuseCoreOptions = { // Langfuse API baseUrl (https://cloud.langfuse.com by default) @@ -55,41 +55,97 @@ export type LangfuseMetadataProperties = { }; // ASYNC -export type CreateLangfuseTraceBody = FixTypes< - paths["/api/public/traces"]["post"]["requestBody"]["content"]["application/json"] ->; -export type CreateLangfuseEventBody = FixTypes< - paths["/api/public/events"]["post"]["requestBody"]["content"]["application/json"] ->; -export type CreateLangfuseSpanBody = FixTypes< - paths["/api/public/spans"]["post"]["requestBody"]["content"]["application/json"] ->; -export type CreateLangfuseGenerationBody = Omit< - FixTypes, - "input" | "output" ->; -export type CreateLangfuseScoreBody = FixTypes< - paths["/api/public/scores"]["post"]["requestBody"]["content"]["application/json"] ->; -export type UpdateLangfuseSpanBody = FixTypes< - paths["/api/public/spans"]["patch"]["requestBody"]["content"]["application/json"] ->; -export type UpdateLangfuseGenerationBody = FixTypes< - paths["/api/public/generations"]["patch"]["requestBody"]["content"]["application/json"] ->; +export type CreateLangfuseTraceBody = { + id?: string | null; + name?: string | null; + userId?: string | null; + externalId?: string | null; + release?: string | null; + version?: string | null; + metadata?: Record | null; + /** @description Make trace publicly accessible via url */ + public?: boolean | null; +}; +export type CreateLangfuseEventBody = { + id?: string | null; + traceId?: string | null; + name?: string | null; + /** Format: date-time */ + startTime?: string | null; + metadata?: Record | null; + input?: Record | null; + output?: Record | null; + level?: components["schemas"]["ObservationLevel"]; + statusMessage?: string | null; + parentObservationId?: string | null; + version?: string | null; +}; +export type CreateLangfuseSpanBody = { + /** Format: date-time */ + endTime?: string | null; +} & CreateLangfuseEventBody; +export type CreateLangfuseGenerationBody = { + /** Format: date-time */ + completionStartTime?: string | null; + model?: string | null; + modelParameters?: { + [key: string]: components["schemas"]["MapValue"] | undefined; + } | null; + prompt?: Record | null; + completion?: Record | null; + usage?: components["schemas"]["Usage"]; +} & CreateLangfuseSpanBody; +export type CreateLangfuseScoreBody = { + id: string; + traceId: string; + name: string; + /** Format: double */ + value: number; + observationId?: string | null; + /** Format: date-time */ + timestamp: string; + comment?: string | null; +}; +export type UpdateLangfuseSpanBody = { + spanId: string; + traceId?: string | null; + /** Format: date-time */ + startTime?: string | null; + /** Format: date-time */ + endTime?: string | null; + name?: string | null; + metadata?: Record | null; + input?: Record | null; + output?: Record | null; + level?: components["schemas"]["ObservationLevel"]; + version?: string | null; + statusMessage?: string | null; +}; +export type UpdateLangfuseGenerationBody = { + generationId: string; + traceId?: string | null; + name?: string | null; + /** Format: date-time */ + startTime?: string | null; + /** Format: date-time */ + endTime?: string | null; + /** Format: date-time */ + completionStartTime?: string | null; + model?: string | null; + modelParameters?: { + [key: string]: components["schemas"]["MapValue"] | undefined; + } | null; + prompt?: Record | null; + version?: string | null; + metadata?: Record | null; + completion?: Record | null; + usage?: components["schemas"]["Usage"]; + level?: components["schemas"]["ObservationLevel"]; + statusMessage?: string | null; +}; export type LangfuseObject = SingleIngestionEvent["type"]; -export const LangfusePostApiRoutes: Record = { - createTrace: ["POST", "/api/public/traces"], - createEvent: ["POST", "/api/public/events"], - createSpan: ["POST", "/api/public/spans"], - updateSpan: ["PATCH", "/api/public/spans"], - createGeneration: ["POST", "/api/public/generations"], - updateGeneration: ["PATCH", "/api/public/generations"], - createScore: ["POST", "/api/public/scores"], -}; - // SYNC export type GetLangfuseDatasetParams = FixTypes< paths["/api/public/datasets/{datasetName}"]["get"]["parameters"]["path"]