Class: Braintrust::BaseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/base_model.rb

Direct Known Subclasses

Models::ACL, Models::Dataset, Models::DatasetFetchPostResponse, Models::DatasetFetchPostResponse::Event, Models::DatasetFetchResponse, Models::DatasetFetchResponse::Event, Models::DatasetInsertResponse, Models::DatasetSummarizeResponse, Models::DatasetSummarizeResponse::DataSummary, Models::Experiment, Models::Experiment::RepoInfo, Models::ExperimentFetchPostResponse, Models::ExperimentFetchPostResponse::Event, Models::ExperimentFetchPostResponse::Event::Context, Models::ExperimentFetchPostResponse::Event::Metrics, Models::ExperimentFetchPostResponse::Event::SpanAttributes, Models::ExperimentFetchResponse, Models::ExperimentFetchResponse::Event, Models::ExperimentFetchResponse::Event::Context, Models::ExperimentFetchResponse::Event::Metrics, Models::ExperimentFetchResponse::Event::SpanAttributes, Models::ExperimentInsertResponse, Models::ExperimentSummarizeResponse, Models::ExperimentSummarizeResponse::Metric, Models::ExperimentSummarizeResponse::Score, Models::Group, Models::LogFetchPostResponse, Models::LogFetchPostResponse::Event, Models::LogFetchPostResponse::Event::Context, Models::LogFetchPostResponse::Event::Metrics, Models::LogFetchPostResponse::Event::SpanAttributes, Models::LogFetchResponse, Models::LogFetchResponse::Event, Models::LogFetchResponse::Event::Context, Models::LogFetchResponse::Event::Metrics, Models::LogFetchResponse::Event::SpanAttributes, Models::LogInsertResponse, Models::Project, Models::Prompt, Models::Prompt::PromptData, Models::Prompt::PromptData::Options, Models::Prompt::PromptData::Origin, Models::Role, Models::User

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Lookup attribute value by key in the object. If this key was not provided when the object was formed (e.g. because the API response did not include that key), returns nil. It is valid to lookup keys that are not in the API spec, for example to access undocumented features. Lookup by anything other than a Symbol is an ArgumentError.

Parameters:

  • key (Symbol)

    Key to look up by.

Returns:

  • (Object)

    Parsed / typed value at the given key, or nil if no data is available.



183
184
185
186
187
188
# File 'lib/braintrust/base_model.rb', line 183

def [](key)
  if !key.instance_of?(Symbol)
    raise ArgumentError, "Expected symbol key for lookup, got #{key.inspect}"
  end
  @data[key]
end

#inspectString

Returns:

  • (String)


191
192
193
# File 'lib/braintrust/base_model.rb', line 191

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)} #{@data.inspect}>"
end

#to_hHash{Symbol => Object} Also known as: to_hash

Returns a Hash of the data underlying this object. Keys are Symbols and values are the parsed / typed domain objects. The return value indicates which values were ever set on the object - i.e. there will be a key in this hash if they ever were, even if the set value was nil. This method is not recursive. The returned value is shared by the object, so it should not be mutated.

Returns:

  • (Hash{Symbol => Object})

    Data for this object.



167
168
169
# File 'lib/braintrust/base_model.rb', line 167

def to_h
  @data
end

#to_sString

Returns:

  • (String)


196
197
198
# File 'lib/braintrust/base_model.rb', line 196

def to_s
  @data.to_s
end