Class: Anthropic::Internal::Type::FileInput Abstract Private

Inherits:
Object
  • Object
show all
Extended by:
Converter
Defined in:
lib/anthropic/internal/type/file_input.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is abstract.

Either Pathname or StringIO, or IO, or Anthropic::Internal::Type::FileInput.

Note: when IO is used, all retries are disabled, since many IO` streams are not rewindable.

Class Method Summary collapse

Methods included from Converter

coerce, dump, inspect, inspect, meta_info, new_coerce_state, type_info

Methods included from Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type

Class Method Details

.==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:



39
# File 'lib/anthropic/internal/type/file_input.rb', line 39

def self.==(other) = other.is_a?(Class) && other <= Anthropic::Internal::Type::FileInput

.===(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:



25
26
27
28
29
30
31
32
# File 'lib/anthropic/internal/type/file_input.rb', line 25

def self.===(other)
  case other
  in Pathname | StringIO | IO | String | Anthropic::FilePart
    true
  else
    false
  end
end

.coerce(value, state:) ⇒ StringIO, Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (StringIO, String, Object)
  • state (Hash{Symbol=>Object})

    .

    @option state [Boolean] :translate_names

    @option state [Boolean] :strictness

    @option state [HashSymbol=>Object] :exactness

    @option state [Class] :error

    @option state [Integer] :branched

Returns:

  • (StringIO, Object)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/anthropic/internal/type/file_input.rb', line 59

def coerce(value, state:)
  exactness = state.fetch(:exactness)
  case value
  in String
    exactness[:yes] += 1
    StringIO.new(value)
  in StringIO
    exactness[:yes] += 1
    value
  else
    state[:error] = TypeError.new("#{value.class} can't be coerced into #{StringIO}")
    exactness[:no] += 1
    value
  end
end

.dump(value, state:) ⇒ Pathname, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • value (Pathname, StringIO, IO, String, Object)
  • state (Hash{Symbol=>Object})

    .

    @option state [Boolean] :can_retry

Returns:

  • (Pathname, StringIO, IO, String, Object)


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/anthropic/internal/type/file_input.rb', line 84

def dump(value, state:)
  # rubocop:disable Lint/DuplicateBranch
  case value
  in IO
    state[:can_retry] = false
  in Anthropic::FilePart if value.content.is_a?(IO)
    state[:can_retry] = false
  else
  end
  # rubocop:enable Lint/DuplicateBranch

  value
end

.to_sorbet_typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Object)


101
102
103
# File 'lib/anthropic/internal/type/file_input.rb', line 101

def to_sorbet_type
  T.any(Pathname, StringIO, IO, String, Anthropic::FilePart)
end