Class: Langfuse::DatasetClient
- Inherits:
-
Object
- Object
- Langfuse::DatasetClient
- Includes:
- TimestampParser
- Defined in:
- lib/langfuse/dataset_client.rb
Overview
Client wrapper for a Langfuse dataset
Provides read access to dataset fields and the ability to run experiments against the dataset’s items. Returned by Client#get_dataset and Client#create_dataset.
Instance Attribute Summary collapse
-
#created_at ⇒ Time?
readonly
Timestamp when the dataset was created.
-
#description ⇒ String?
readonly
Optional description of the dataset.
-
#id ⇒ String
readonly
Unique identifier for the dataset.
-
#metadata ⇒ Hash
readonly
Additional metadata as key-value pairs.
-
#name ⇒ String
readonly
Human-readable name of the dataset.
-
#updated_at ⇒ Time?
readonly
Timestamp when the dataset was last updated.
Instance Method Summary collapse
-
#initialize(dataset_data, client: nil) ⇒ DatasetClient
constructor
Initialize a new dataset client from API response data.
-
#items ⇒ Array<DatasetItemClient>
Lazily-parsed dataset items.
-
#run_experiment(name:, task:, description: nil, evaluators: [], run_evaluators: [], metadata: nil, run_name: nil) ⇒ ExperimentResult
Run an experiment against all items in this dataset.
-
#url ⇒ String?
Generate URL for viewing this dataset in Langfuse UI.
Constructor Details
#initialize(dataset_data, client: nil) ⇒ DatasetClient
Initialize a new dataset client from API response data
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/langfuse/dataset_client.rb', line 43 def initialize(dataset_data, client: nil) validate_dataset_data!(dataset_data) @id = dataset_data["id"] @name = dataset_data["name"] @description = dataset_data["description"] @metadata = dataset_data["metadata"] || {} @created_at = (dataset_data["createdAt"]) @updated_at = (dataset_data["updatedAt"]) @raw_items = dataset_data["items"] || [] @client = client end |
Instance Attribute Details
#created_at ⇒ Time? (readonly)
Returns Timestamp when the dataset was created.
33 34 35 |
# File 'lib/langfuse/dataset_client.rb', line 33 def created_at @created_at end |
#description ⇒ String? (readonly)
Returns Optional description of the dataset.
27 28 29 |
# File 'lib/langfuse/dataset_client.rb', line 27 def description @description end |
#id ⇒ String (readonly)
Returns Unique identifier for the dataset.
21 22 23 |
# File 'lib/langfuse/dataset_client.rb', line 21 def id @id end |
#metadata ⇒ Hash (readonly)
Returns Additional metadata as key-value pairs.
30 31 32 |
# File 'lib/langfuse/dataset_client.rb', line 30 def @metadata end |
#name ⇒ String (readonly)
Returns Human-readable name of the dataset.
24 25 26 |
# File 'lib/langfuse/dataset_client.rb', line 24 def name @name end |
#updated_at ⇒ Time? (readonly)
Returns Timestamp when the dataset was last updated.
36 37 38 |
# File 'lib/langfuse/dataset_client.rb', line 36 def updated_at @updated_at end |
Instance Method Details
#items ⇒ Array<DatasetItemClient>
Lazily-parsed dataset items
58 59 60 61 62 63 64 |
# File 'lib/langfuse/dataset_client.rb', line 58 def items @items ||= if @raw_items.empty? && @client @client.list_dataset_items(dataset_name: @name) else @raw_items.map { |item_data| DatasetItemClient.new(item_data, client: @client) } end end |
#run_experiment(name:, task:, description: nil, evaluators: [], run_evaluators: [], metadata: nil, run_name: nil) ⇒ ExperimentResult
Run an experiment against all items in this dataset
rubocop:disable Metrics/ParameterLists
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/langfuse/dataset_client.rb', line 88 def run_experiment(name:, task:, description: nil, evaluators: [], run_evaluators: [], metadata: nil, run_name: nil) raise ArgumentError, "client is required for this operation" unless @client @client.run_experiment( name: name, data: items, task: task, evaluators: evaluators, run_evaluators: run_evaluators, metadata: , description: description, run_name: run_name ) end |
#url ⇒ String?
Generate URL for viewing this dataset in Langfuse UI
69 70 71 72 73 |
# File 'lib/langfuse/dataset_client.rb', line 69 def url return nil unless @client @client.dataset_url(@id) end |