Class: Langfuse::DatasetItemClient
- Inherits:
-
Object
- Object
- Langfuse::DatasetItemClient
- Includes:
- TimestampParser
- Defined in:
- lib/langfuse/dataset_item_client.rb
Overview
Client wrapper for a single Langfuse dataset item
Provides read access to item fields and operations to link items to traces or run tasks within a traced context. Returned by Client#get_dataset_item, Client#create_dataset_item, and Langfuse::DatasetClient#items.
Instance Attribute Summary collapse
-
#created_at ⇒ Time?
readonly
Timestamp when the item was created.
-
#dataset_id ⇒ String
readonly
Identifier of the parent dataset.
-
#expected_output ⇒ Object?
readonly
Expected output for evaluation.
-
#id ⇒ String
readonly
Unique identifier for the dataset item.
-
#input ⇒ Object?
readonly
Input data for the dataset item.
-
#metadata ⇒ Hash
readonly
Additional metadata as key-value pairs.
-
#source_observation_id ⇒ String?
readonly
Observation ID that produced this item.
-
#source_trace_id ⇒ String?
readonly
Trace ID that produced this item.
-
#status ⇒ String
readonly
Item status (ACTIVE or ARCHIVED).
-
#updated_at ⇒ Time?
readonly
Timestamp when the item was last updated.
Instance Method Summary collapse
-
#active? ⇒ Boolean
True if the item is active.
-
#archived? ⇒ Boolean
True if the item is archived.
-
#initialize(item_data, client: nil) ⇒ DatasetItemClient
constructor
Initialize a new dataset item client from API response data.
-
#link(trace_id:, run_name:, observation_id: nil, metadata: nil, run_description: nil) ⇒ Hash
Link this dataset item to a trace within a named run.
-
#run(run_name:, run_description: nil, run_metadata: nil) {|span| ... } ⇒ Object
Run a block within a traced context and auto-link to this dataset item.
Constructor Details
#initialize(item_data, client: nil) ⇒ DatasetItemClient
Initialize a new dataset item client from API response data
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/langfuse/dataset_item_client.rb', line 56 def initialize(item_data, client: nil) validate_item_data!(item_data) @id = item_data["id"] @dataset_id = item_data["datasetId"] @input = item_data["input"] @expected_output = item_data["expectedOutput"] @metadata = item_data["metadata"] || {} @source_trace_id = item_data["sourceTraceId"] @source_observation_id = item_data["sourceObservationId"] @status = item_data["status"] || "ACTIVE" @created_at = (item_data["createdAt"]) @updated_at = (item_data["updatedAt"]) @client = client end |
Instance Attribute Details
#created_at ⇒ Time? (readonly)
Returns Timestamp when the item was created.
46 47 48 |
# File 'lib/langfuse/dataset_item_client.rb', line 46 def created_at @created_at end |
#dataset_id ⇒ String (readonly)
Returns Identifier of the parent dataset.
25 26 27 |
# File 'lib/langfuse/dataset_item_client.rb', line 25 def dataset_id @dataset_id end |
#expected_output ⇒ Object? (readonly)
Returns Expected output for evaluation.
31 32 33 |
# File 'lib/langfuse/dataset_item_client.rb', line 31 def expected_output @expected_output end |
#id ⇒ String (readonly)
Returns Unique identifier for the dataset item.
22 23 24 |
# File 'lib/langfuse/dataset_item_client.rb', line 22 def id @id end |
#input ⇒ Object? (readonly)
Returns Input data for the dataset item.
28 29 30 |
# File 'lib/langfuse/dataset_item_client.rb', line 28 def input @input end |
#metadata ⇒ Hash (readonly)
Returns Additional metadata as key-value pairs.
34 35 36 |
# File 'lib/langfuse/dataset_item_client.rb', line 34 def @metadata end |
#source_observation_id ⇒ String? (readonly)
Returns Observation ID that produced this item.
40 41 42 |
# File 'lib/langfuse/dataset_item_client.rb', line 40 def source_observation_id @source_observation_id end |
#source_trace_id ⇒ String? (readonly)
Returns Trace ID that produced this item.
37 38 39 |
# File 'lib/langfuse/dataset_item_client.rb', line 37 def source_trace_id @source_trace_id end |
#status ⇒ String (readonly)
Returns Item status (ACTIVE or ARCHIVED).
43 44 45 |
# File 'lib/langfuse/dataset_item_client.rb', line 43 def status @status end |
#updated_at ⇒ Time? (readonly)
Returns Timestamp when the item was last updated.
49 50 51 |
# File 'lib/langfuse/dataset_item_client.rb', line 49 def updated_at @updated_at end |
Instance Method Details
#active? ⇒ Boolean
Returns true if the item is active.
72 |
# File 'lib/langfuse/dataset_item_client.rb', line 72 def active? = status == "ACTIVE" |
#archived? ⇒ Boolean
Returns true if the item is archived.
75 |
# File 'lib/langfuse/dataset_item_client.rb', line 75 def archived? = status == "ARCHIVED" |
#link(trace_id:, run_name:, observation_id: nil, metadata: nil, run_description: nil) ⇒ Hash
Link this dataset item to a trace within a named run
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/langfuse/dataset_item_client.rb', line 86 def link(trace_id:, run_name:, observation_id: nil, metadata: nil, run_description: nil) require_client! @client.create_dataset_run_item( dataset_item_id: @id, run_name: run_name, trace_id: trace_id, observation_id: observation_id, metadata: , run_description: run_description ) end |
#run(run_name:, run_description: nil, run_metadata: nil) {|span| ... } ⇒ Object
Run a block within a traced context and auto-link to this dataset item
Lower-level alternative to Client#run_experiment for single-item execution with direct span access. Matches Python SDK’s ‘item.run()` context manager pattern.
Executes the block inside an observed span, flushes the trace, then creates a dataset run item linking this item to the resulting trace.
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/langfuse/dataset_item_client.rb', line 115 def run(run_name:, run_description: nil, run_metadata: nil, &block) require_client! raise ArgumentError, "block is required" unless block output, trace_id, observation_id, task_error = execute_in_trace(run_name, , &block) Langfuse.force_flush(timeout: FLUSH_TIMEOUT) link(trace_id: trace_id, observation_id: observation_id, run_name: run_name, run_description: run_description, metadata: ) raise task_error if task_error output end |