Class: TurnKit::MediaAnalysisResult

Inherits:
Object
  • Object
show all
Defined in:
lib/turnkit/media_analysis_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text: "", data: nil, model: nil, provider: nil, usage: Usage.new, params: {}, media: {}, metadata: {}, error: nil) ⇒ MediaAnalysisResult

Returns a new instance of MediaAnalysisResult.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/turnkit/media_analysis_result.rb', line 11

def initialize(text: "", data: nil, model: nil, provider: nil, usage: Usage.new, params: {}, media: {}, metadata: {}, error: nil, **)
  @text = text.to_s
  @data = data
  @model = model
  @provider = provider
  @usage = usage.is_a?(Usage) ? usage : Usage.from_h(usage || {})
  @params = params || {}
  @media = media || {}
  @metadata =  || {}
  @error = error
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def error
  @error
end

#mediaObject (readonly)

Returns the value of attribute media.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def media
  @media
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def 
  @metadata
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def model
  @model
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def params
  @params
end

#providerObject (readonly)

Returns the value of attribute provider.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def provider
  @provider
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def text
  @text
end

#usageObject (readonly)

Returns the value of attribute usage.



5
6
7
# File 'lib/turnkit/media_analysis_result.rb', line 5

def usage
  @usage
end

Class Method Details

.from_h(value) ⇒ Object



7
8
9
# File 'lib/turnkit/media_analysis_result.rb', line 7

def self.from_h(value)
  new(**value.transform_keys(&:to_sym))
end

Instance Method Details

#costObject



29
30
31
# File 'lib/turnkit/media_analysis_result.rb', line 29

def cost
  Cost.from_usage(usage, model: model)
end

#data?Boolean Also known as: structured?

Returns:

  • (Boolean)


23
24
25
# File 'lib/turnkit/media_analysis_result.rb', line 23

def data?
  !data.nil?
end

#to_hObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/turnkit/media_analysis_result.rb', line 33

def to_h
  {
    "text" => text,
    "data" => data,
    "model" => model,
    "provider" => provider,
    "usage" => usage.to_h,
    "cost" => cost.to_h,
    "params" => params,
    "media" => media,
    "metadata" => ,
    "error" => error
  }.compact
end