Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(cost): allow all usage types #486

Merged
merged 8 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions integration-test/langfuse-integration-langchain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,9 @@ describe("Langchain", () => {
role: "assistant",
},
usage: {
completionTokens: expect.any(Number),
promptTokens: expect.any(Number),
totalTokens: expect.any(Number),
input: expect.any(Number),
output: expect.any(Number),
total: expect.any(Number),
},
version: "1.0.0",
});
Expand Down
121 changes: 113 additions & 8 deletions langfuse-core/openapi-spec/openapi-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,7 @@ components:
type: string
description: >-
The content of the comment. May include markdown. Currently limited
to 500 characters.
to 3000 characters.
authorUserId:
type: string
nullable: true
Expand Down Expand Up @@ -2627,7 +2627,9 @@ components:
usage:
$ref: '#/components/schemas/Usage'
nullable: true
description: The usage data of the observation
description: >-
(Deprecated. Use usageDetails and costDetails instead.) The usage
data of the observation
level:
$ref: '#/components/schemas/ObservationLevel'
description: The level of the observation
Expand All @@ -2643,6 +2645,25 @@ components:
type: string
nullable: true
description: The prompt ID associated with the observation
usageDetails:
type: object
additionalProperties:
type: integer
nullable: true
description: >-
The usage details of the observation. Key is the name of the usage
metric, value is the number of units consumed. The total key is the
sum of all (non-total) usage metrics or the total value ingested.
costDetails:
hassiebp marked this conversation as resolved.
Show resolved Hide resolved
type: object
additionalProperties:
type: number
format: double
nullable: true
description: >-
The cost details of the observation. Key is the name of the cost
metric, value is the cost in USD. The total key is the sum of all
(non-total) cost metrics or the total value ingested.
required:
- id
- type
Expand Down Expand Up @@ -2683,17 +2704,23 @@ components:
type: number
format: double
nullable: true
description: The calculated cost of the input in USD
description: >-
(Deprecated. Use usageDetails and costDetails instead.) The
calculated cost of the input in USD
calculatedOutputCost:
type: number
format: double
nullable: true
description: The calculated cost of the output in USD
description: >-
(Deprecated. Use usageDetails and costDetails instead.) The
calculated cost of the output in USD
calculatedTotalCost:
type: number
format: double
nullable: true
description: The calculated total cost in USD
description: >-
(Deprecated. Use usageDetails and costDetails instead.) The
calculated total cost in USD
latency:
type: number
format: double
Expand All @@ -2709,7 +2736,9 @@ components:
Usage:
title: Usage
type: object
description: Standard interface for usage and cost
description: >-
(Deprecated. Use usageDetails and costDetails instead.) Standard
interface for usage and cost
properties:
input:
type: integer
Expand Down Expand Up @@ -3608,6 +3637,15 @@ components:
usage:
$ref: '#/components/schemas/IngestionUsage'
nullable: true
usageDetails:
$ref: '#/components/schemas/UsageDetails'
nullable: true
costDetails:
type: object
additionalProperties:
type: number
format: double
nullable: true
promptName:
type: string
nullable: true
Expand Down Expand Up @@ -3638,6 +3676,15 @@ components:
promptName:
type: string
nullable: true
usageDetails:
$ref: '#/components/schemas/UsageDetails'
nullable: true
costDetails:
type: object
additionalProperties:
type: number
format: double
nullable: true
promptVersion:
type: integer
nullable: true
Expand Down Expand Up @@ -3955,6 +4002,37 @@ components:
required:
- successes
- errors
OpenAIUsageSchema:
title: OpenAIUsageSchema
type: object
properties:
prompt_tokens:
hassiebp marked this conversation as resolved.
Show resolved Hide resolved
type: integer
completion_tokens:
type: integer
total_tokens:
type: integer
prompt_tokens_details:
type: object
additionalProperties:
type: integer
nullable: true
completion_tokens_details:
type: object
additionalProperties:
type: integer
nullable: true
required:
- prompt_tokens
- completion_tokens
- total_tokens
UsageDetails:
title: UsageDetails
oneOf:
- type: object
additionalProperties:
type: integer
- $ref: '#/components/schemas/OpenAIUsageSchema'
GetMediaResponse:
title: GetMediaResponse
type: object
Expand Down Expand Up @@ -4058,8 +4136,35 @@ components:
title: MediaContentType
type: string
enum:
- >-
image/png","image/jpeg","image/jpg","image/webp","image/gif","image/svg+xml","image/tiff","image/bmp","audio/mpeg","audio/mp3","audio/wav","audio/ogg","audio/oga","audio/aac","audio/mp4","audio/flac","video/mp4","video/webm","text/plain","text/html","text/css","text/csv","application/pdf","application/msword","application/vnd.ms-excel","application/zip","application/json","application/xml","application/octet-stream
- image/png
- image/jpeg
- image/jpg
- image/webp
- image/gif
- image/svg+xml
- image/tiff
- image/bmp
- audio/mpeg
- audio/mp3
- audio/wav
- audio/ogg
- audio/oga
- audio/aac
- audio/mp4
- audio/flac
- video/mp4
- video/webm
- text/plain
- text/html
- text/css
- text/csv
- application/pdf
- application/msword
- application/vnd.ms-excel
- application/zip
- application/json
- application/xml
- application/octet-stream
description: The MIME type of the media record
DailyMetrics:
title: DailyMetrics
Expand Down
68 changes: 61 additions & 7 deletions langfuse-core/src/openapi/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ export interface components {
objectType: string;
/** @description The id of the object to attach the comment to. If this does not reference a valid existing object, an error will be thrown. */
objectId: string;
/** @description The content of the comment. May include markdown. Currently limited to 500 characters. */
/** @description The content of the comment. May include markdown. Currently limited to 3000 characters. */
content: string;
/** @description The id of the user who created the comment. */
authorUserId?: string | null;
Expand Down Expand Up @@ -657,7 +657,7 @@ export interface components {
metadata?: unknown;
/** @description The output data of the observation */
output?: unknown;
/** @description The usage data of the observation */
/** @description (Deprecated. Use usageDetails and costDetails instead.) The usage data of the observation */
usage?: components["schemas"]["Usage"];
/** @description The level of the observation */
level: components["schemas"]["ObservationLevel"];
Expand All @@ -667,6 +667,14 @@ export interface components {
parentObservationId?: string | null;
/** @description The prompt ID associated with the observation */
promptId?: string | null;
/** @description The usage details of the observation. Key is the name of the usage metric, value is the number of units consumed. The total key is the sum of all (non-total) usage metrics or the total value ingested. */
usageDetails?: {
[key: string]: number;
} | null;
/** @description The cost details of the observation. Key is the name of the cost metric, value is the cost in USD. The total key is the sum of all (non-total) cost metrics or the total value ingested. */
costDetails?: {
[key: string]: number;
} | null;
};
/** ObservationsView */
ObservationsView: {
Expand All @@ -693,17 +701,17 @@ export interface components {
totalPrice?: number | null;
/**
* Format: double
* @description The calculated cost of the input in USD
* @description (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the input in USD
*/
calculatedInputCost?: number | null;
/**
* Format: double
* @description The calculated cost of the output in USD
* @description (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the output in USD
*/
calculatedOutputCost?: number | null;
/**
* Format: double
* @description The calculated total cost in USD
* @description (Deprecated. Use usageDetails and costDetails instead.) The calculated total cost in USD
*/
calculatedTotalCost?: number | null;
/**
Expand All @@ -719,7 +727,7 @@ export interface components {
} & components["schemas"]["Observation"];
/**
* Usage
* @description Standard interface for usage and cost
* @description (Deprecated. Use usageDetails and costDetails instead.) Standard interface for usage and cost
*/
Usage: {
/** @description Number of input units (e.g. tokens) */
Expand Down Expand Up @@ -1156,6 +1164,10 @@ export interface components {
[key: string]: components["schemas"]["MapValue"];
} | null;
usage?: components["schemas"]["IngestionUsage"];
usageDetails?: components["schemas"]["UsageDetails"];
costDetails?: {
[key: string]: number;
} | null;
promptName?: string | null;
promptVersion?: number | null;
} & components["schemas"]["CreateSpanBody"];
Expand All @@ -1169,6 +1181,10 @@ export interface components {
} | null;
usage?: components["schemas"]["IngestionUsage"];
promptName?: string | null;
usageDetails?: components["schemas"]["UsageDetails"];
costDetails?: {
[key: string]: number;
} | null;
promptVersion?: number | null;
} & components["schemas"]["UpdateSpanBody"];
/** ObservationBody */
Expand Down Expand Up @@ -1299,6 +1315,24 @@ export interface components {
successes: components["schemas"]["IngestionSuccess"][];
errors: components["schemas"]["IngestionError"][];
};
/** OpenAIUsageSchema */
OpenAIUsageSchema: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
prompt_tokens_details?: {
[key: string]: number;
} | null;
completion_tokens_details?: {
[key: string]: number;
} | null;
};
hassiebp marked this conversation as resolved.
Show resolved Hide resolved
/** UsageDetails */
UsageDetails:
| {
[key: string]: number;
}
| components["schemas"]["OpenAIUsageSchema"];
/** GetMediaResponse */
GetMediaResponse: {
/** @description The unique langfuse identifier of a media record */
Expand Down Expand Up @@ -1362,11 +1396,31 @@ export interface components {
| "image/jpeg"
| "image/jpg"
| "image/webp"
| "image/gif"
| "image/svg+xml"
| "image/tiff"
| "image/bmp"
| "audio/mpeg"
| "audio/mp3"
| "audio/wav"
| "audio/ogg"
| "audio/oga"
| "audio/aac"
| "audio/mp4"
| "audio/flac"
| "video/mp4"
| "video/webm"
| "text/plain"
| "application/pdf";
| "text/html"
| "text/css"
| "text/csv"
| "application/pdf"
| "application/msword"
| "application/vnd.ms-excel"
| "application/zip"
| "application/json"
| "application/xml"
| "application/octet-stream";
/** DailyMetrics */
DailyMetrics: {
/** @description A list of daily metrics, only days with ingested data are included. */
Expand Down
1 change: 1 addition & 0 deletions langfuse-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export type EventBody =
| UpdateLangfuseGenerationBody;

export type Usage = FixTypes<components["schemas"]["IngestionUsage"]>;
export type UsageDetails = FixTypes<components["schemas"]["UsageDetails"]>;
export type CreateLangfuseGenerationBody = FixTypes<components["schemas"]["CreateGenerationBody"]>;
export type UpdateLangfuseGenerationBody = FixTypes<components["schemas"]["UpdateGenerationBody"]>;

Expand Down
Loading
Loading