| | | 1 | | using System.Text.Json; |
| | | 2 | | using System.Text.Json.Serialization; |
| | | 3 | | |
| | | 4 | | namespace Orchestrator.Infrastructure.Langfuse; |
| | | 5 | | |
| | | 6 | | public sealed record LangfuseCreateDatasetRequest( |
| | | 7 | | [property: JsonPropertyName("name")] string Name, |
| | | 8 | | [property: JsonPropertyName("description")] string? Description = null, |
| | | 9 | | [property: JsonPropertyName("metadata")] object? Metadata = null, |
| | | 10 | | [property: JsonPropertyName("inputSchema")] JsonElement? InputSchema = null, |
| | | 11 | | [property: JsonPropertyName("expectedOutputSchema")] JsonElement? ExpectedOutputSchema = null); |
| | | 12 | | |
| | | 13 | | public sealed record LangfuseCreateDatasetItemRequest( |
| | | 14 | | [property: JsonPropertyName("id")] string Id, |
| | | 15 | | [property: JsonPropertyName("datasetName")] string? DatasetName = null, |
| | | 16 | | [property: JsonPropertyName("input")] object? Input = null, |
| | | 17 | | [property: JsonPropertyName("expectedOutput")] object? ExpectedOutput = null, |
| | | 18 | | [property: JsonPropertyName("metadata")] object? Metadata = null, |
| | | 19 | | [property: JsonPropertyName("status")] string? Status = null); |
| | | 20 | | |
| | | 21 | | public sealed record LangfuseCreateDatasetRunItemRequest( |
| | | 22 | | [property: JsonPropertyName("runName")] string RunName, |
| | | 23 | | [property: JsonPropertyName("datasetItemId")] string DatasetItemId, |
| | | 24 | | [property: JsonPropertyName("traceId")] string TraceId, |
| | | 25 | | [property: JsonPropertyName("runDescription")] string? RunDescription = null, |
| | | 26 | | [property: JsonPropertyName("metadata")] object? Metadata = null, |
| | | 27 | | [property: JsonPropertyName("observationId")] string? ObservationId = null, |
| | | 28 | | [property: JsonPropertyName("createdAt")] DateTimeOffset? CreatedAt = null); |
| | | 29 | | |
| | | 30 | | public sealed record LangfuseCreateScoreRequest( |
| | | 31 | | [property: JsonPropertyName("name")] string Name, |
| | | 32 | | [property: JsonPropertyName("value")] double Value, |
| | | 33 | | [property: JsonPropertyName("traceId")] string? TraceId = null, |
| | | 34 | | [property: JsonPropertyName("observationId")] string? ObservationId = null, |
| | | 35 | | [property: JsonPropertyName("datasetRunId")] string? DatasetRunId = null, |
| | | 36 | | [property: JsonPropertyName("dataType")] string? DataType = null, |
| | | 37 | | [property: JsonPropertyName("comment")] string? Comment = null, |
| | | 38 | | [property: JsonPropertyName("id")] string? Id = null, |
| | | 39 | | [property: JsonPropertyName("metadata")] object? Metadata = null, |
| | | 40 | | [property: JsonPropertyName("configId")] string? ConfigId = null, |
| | | 41 | | [property: JsonPropertyName("environment")] string? Environment = null); |
| | | 42 | | |
| | 1 | 43 | | public sealed record LangfuseListScoresRequest( |
| | 1 | 44 | | string? Name = null, |
| | 1 | 45 | | string? DatasetRunId = null, |
| | 1 | 46 | | string? SessionId = null, |
| | 1 | 47 | | string? Filter = null, |
| | 1 | 48 | | string? TraceId = null, |
| | 1 | 49 | | int Page = 1, |
| | 1 | 50 | | int Limit = 100, |
| | 1 | 51 | | string? Fields = "score"); |
| | | 52 | | |
| | | 53 | | public sealed record LangfuseListDatasetItemsRequest( |
| | | 54 | | string? DatasetName = null, |
| | | 55 | | string? Version = null, |
| | | 56 | | int Page = 1, |
| | | 57 | | int Limit = 100); |
| | | 58 | | |
| | | 59 | | public sealed record LangfuseListTracesRequest( |
| | | 60 | | string? SessionId = null, |
| | | 61 | | int Page = 1, |
| | | 62 | | int Limit = 100, |
| | | 63 | | string? Fields = null); |
| | | 64 | | |
| | | 65 | | public sealed record LangfuseListObservationsRequest( |
| | | 66 | | string? SessionId = null, |
| | | 67 | | int Limit = 1000, |
| | | 68 | | string? Cursor = null, |
| | | 69 | | string? Fields = null); |
| | | 70 | | |
| | | 71 | | public sealed record LangfuseCreateScoreResponse( |
| | | 72 | | [property: JsonPropertyName("id")] string Id); |
| | | 73 | | |
| | | 74 | | public sealed record LangfusePrompt( |
| | | 75 | | [property: JsonPropertyName("name")] string Name, |
| | | 76 | | [property: JsonPropertyName("version")] int Version, |
| | | 77 | | [property: JsonPropertyName("type")] string? Type, |
| | | 78 | | [property: JsonPropertyName("prompt")] JsonElement Prompt, |
| | | 79 | | [property: JsonPropertyName("labels")] IReadOnlyList<string>? Labels, |
| | | 80 | | [property: JsonPropertyName("tags")] IReadOnlyList<string>? Tags, |
| | | 81 | | [property: JsonPropertyName("config")] JsonElement Config) |
| | | 82 | | { |
| | | 83 | | public string GetTextPrompt() |
| | | 84 | | { |
| | | 85 | | if (Prompt.ValueKind != JsonValueKind.String) |
| | | 86 | | { |
| | | 87 | | throw new InvalidOperationException( |
| | | 88 | | $"Langfuse prompt '{Name}' version {Version} is not a text prompt."); |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | return Prompt.GetString() |
| | | 92 | | ?? throw new InvalidOperationException( |
| | | 93 | | $"Langfuse prompt '{Name}' version {Version} contains an empty prompt value."); |
| | | 94 | | } |
| | | 95 | | } |
| | | 96 | | |
| | | 97 | | public sealed record LangfuseDataset( |
| | | 98 | | [property: JsonPropertyName("id")] string Id, |
| | | 99 | | [property: JsonPropertyName("name")] string Name, |
| | | 100 | | [property: JsonPropertyName("description")] string? Description, |
| | | 101 | | [property: JsonPropertyName("metadata")] JsonElement Metadata, |
| | | 102 | | [property: JsonPropertyName("inputSchema")] JsonElement InputSchema, |
| | | 103 | | [property: JsonPropertyName("expectedOutputSchema")] JsonElement ExpectedOutputSchema); |
| | | 104 | | |
| | | 105 | | public sealed record LangfuseDatasetItem( |
| | | 106 | | [property: JsonPropertyName("id")] string Id, |
| | | 107 | | [property: JsonPropertyName("datasetId")] string DatasetId, |
| | | 108 | | [property: JsonPropertyName("datasetName")] string? DatasetName, |
| | | 109 | | [property: JsonPropertyName("input")] JsonElement Input, |
| | | 110 | | [property: JsonPropertyName("expectedOutput")] JsonElement ExpectedOutput, |
| | | 111 | | [property: JsonPropertyName("metadata")] JsonElement Metadata, |
| | | 112 | | [property: JsonPropertyName("status")] string? Status); |
| | | 113 | | |
| | | 114 | | public sealed record LangfuseDatasetRunItem( |
| | | 115 | | [property: JsonPropertyName("id")] string Id, |
| | | 116 | | [property: JsonPropertyName("datasetRunId")] string DatasetRunId, |
| | | 117 | | [property: JsonPropertyName("datasetRunName")] string DatasetRunName, |
| | | 118 | | [property: JsonPropertyName("datasetItemId")] string DatasetItemId, |
| | | 119 | | [property: JsonPropertyName("traceId")] string TraceId, |
| | | 120 | | [property: JsonPropertyName("observationId")] string? ObservationId, |
| | | 121 | | [property: JsonPropertyName("createdAt")] DateTimeOffset CreatedAt, |
| | | 122 | | [property: JsonPropertyName("updatedAt")] DateTimeOffset UpdatedAt); |
| | | 123 | | |
| | | 124 | | public sealed record LangfuseDatasetRunWithItems( |
| | | 125 | | [property: JsonPropertyName("id")] string Id, |
| | | 126 | | [property: JsonPropertyName("name")] string Name, |
| | | 127 | | [property: JsonPropertyName("datasetId")] string DatasetId, |
| | | 128 | | [property: JsonPropertyName("datasetName")] string DatasetName, |
| | | 129 | | [property: JsonPropertyName("description")] string? Description, |
| | | 130 | | [property: JsonPropertyName("metadata")] JsonElement Metadata, |
| | | 131 | | [property: JsonPropertyName("datasetRunItems")] IReadOnlyList<LangfuseDatasetRunItem> DatasetRunItems); |
| | | 132 | | |
| | | 133 | | public sealed record LangfuseScore( |
| | | 134 | | [property: JsonPropertyName("id")] string Id, |
| | | 135 | | [property: JsonPropertyName("name")] string Name, |
| | | 136 | | [property: JsonPropertyName("value")] double? Value, |
| | | 137 | | [property: JsonPropertyName("traceId")] string? TraceId, |
| | | 138 | | [property: JsonPropertyName("observationId")] string? ObservationId, |
| | | 139 | | [property: JsonPropertyName("datasetRunId")] string? DatasetRunId, |
| | | 140 | | [property: JsonPropertyName("dataType")] string? DataType, |
| | | 141 | | [property: JsonPropertyName("source")] string? Source, |
| | | 142 | | [property: JsonPropertyName("metadata")] JsonElement Metadata, |
| | | 143 | | [property: JsonPropertyName("createdAt")] DateTimeOffset? CreatedAt, |
| | | 144 | | [property: JsonPropertyName("updatedAt")] DateTimeOffset? UpdatedAt); |
| | | 145 | | |
| | | 146 | | public sealed record LangfuseObservationDetail( |
| | | 147 | | [property: JsonPropertyName("id")] string Id, |
| | | 148 | | [property: JsonPropertyName("traceId")] string TraceId, |
| | | 149 | | [property: JsonPropertyName("type")] string? Type, |
| | | 150 | | [property: JsonPropertyName("name")] string? Name, |
| | | 151 | | [property: JsonPropertyName("output")] JsonElement Output, |
| | | 152 | | [property: JsonPropertyName("metadata")] JsonElement Metadata); |
| | | 153 | | |
| | | 154 | | public sealed record LangfuseTraceWithDetails( |
| | | 155 | | [property: JsonPropertyName("id")] string Id, |
| | | 156 | | [property: JsonPropertyName("name")] string? Name, |
| | | 157 | | [property: JsonPropertyName("metadata")] JsonElement Metadata, |
| | | 158 | | [property: JsonPropertyName("output")] JsonElement Output, |
| | | 159 | | [property: JsonPropertyName("scores")] IReadOnlyList<LangfuseScore>? Scores, |
| | | 160 | | [property: JsonPropertyName("observations")] IReadOnlyList<LangfuseObservationDetail>? Observations, |
| | | 161 | | [property: JsonPropertyName("tags")] IReadOnlyList<string>? Tags); |
| | | 162 | | |
| | | 163 | | public sealed record LangfusePaginationMeta( |
| | | 164 | | [property: JsonPropertyName("page")] int Page, |
| | | 165 | | [property: JsonPropertyName("limit")] int Limit, |
| | | 166 | | [property: JsonPropertyName("totalItems")] int TotalItems, |
| | | 167 | | [property: JsonPropertyName("totalPages")] int TotalPages); |
| | | 168 | | |
| | | 169 | | public sealed record LangfusePaginatedResponse<T>( |
| | | 170 | | [property: JsonPropertyName("data")] IReadOnlyList<T> Data, |
| | | 171 | | [property: JsonPropertyName("meta")] LangfusePaginationMeta Meta); |
| | | 172 | | |
| | | 173 | | public sealed record LangfuseCursorPaginationMeta( |
| | | 174 | | [property: JsonPropertyName("cursor")] string? Cursor); |
| | | 175 | | |
| | | 176 | | public sealed record LangfuseCursorPaginatedResponse<T>( |
| | | 177 | | [property: JsonPropertyName("data")] IReadOnlyList<T> Data, |
| | | 178 | | [property: JsonPropertyName("meta")] LangfuseCursorPaginationMeta Meta); |