Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdeichmann committed Dec 11, 2023
1 parent 55e47ce commit 0687d76
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 38 deletions.
10 changes: 5 additions & 5 deletions langfuse-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ abstract class LangfuseCoreStateless {

const parsedBody: CreateLangfuseEventBody = {
id,
startTime: bodyStartTime ?? new Date(),
startTime: bodyStartTime ?? currentISOTime(),
...rest,
};
this.enqueue("observation-create", parsedBody);
Expand All @@ -165,7 +165,7 @@ abstract class LangfuseCoreStateless {

const parsedBody: CreateLangfuseSpanBody = {
id,
startTime: bodyStartTime ?? new Date(),
startTime: bodyStartTime ?? currentISOTime(),
...rest,
};
this.enqueue("observation-create", parsedBody);
Expand All @@ -179,7 +179,7 @@ abstract class LangfuseCoreStateless {

const parsedBody: CreateLangfuseGenerationBody = {
id,
startTime: bodyStartTime ?? new Date(),
startTime: bodyStartTime ?? currentISOTime(),
...rest,
};
this.enqueue("observation-create", parsedBody);
Expand Down Expand Up @@ -667,7 +667,7 @@ export class LangfuseSpanClient extends LangfuseObservationClient {
...body,
spanId: this.id,
traceId: this.traceId,
endTime: new Date(),
endTime: currentISOTime(),
});
return this;
}
Expand All @@ -692,7 +692,7 @@ export class LangfuseGenerationClient extends LangfuseObservationClient {
...body,
generationId: this.id,
traceId: this.traceId,
endTime: new Date(),
endTime: currentISOTime(),
});
return this;
}
Expand Down
122 changes: 89 additions & 33 deletions langfuse-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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<paths["/api/public/generations"]["post"]["requestBody"]["content"]["application/json"]>,
"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<string, unknown> | 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<string, unknown> | null;
input?: Record<string, unknown> | null;
output?: Record<string, unknown> | 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<string, unknown> | null;
completion?: Record<string, unknown> | 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<string, unknown> | null;
input?: Record<string, unknown> | null;
output?: Record<string, unknown> | 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<string, unknown> | null;
version?: string | null;
metadata?: Record<string, unknown> | null;
completion?: Record<string, unknown> | null;
usage?: components["schemas"]["Usage"];
level?: components["schemas"]["ObservationLevel"];
statusMessage?: string | null;
};

export type LangfuseObject = SingleIngestionEvent["type"];

export const LangfusePostApiRoutes: Record<LangfuseObject, [LangfuseQueueItem["method"], keyof paths]> = {
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"]
Expand Down

0 comments on commit 0687d76

Please sign in to comment.