Class: Vellum::SlimDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/types/slim_document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, last_uploaded_at:, label:, document_to_document_indexes:, external_id: nil, processing_state: nil, processing_failure_reason: nil, status: nil, keywords: nil, metadata: nil, additional_properties: nil) ⇒ SlimDocument

Parameters:

  • id (String)

    Vellum-generated ID that uniquely identifies this document.

  • external_id (String) (defaults to: nil)

    The external ID that was originally provided when uploading the document.

  • last_uploaded_at (DateTime)

    A timestamp representing when this document was most recently uploaded.

  • label (String)

    Human-friendly name for this document.

  • processing_state (PROCESSING_STATE_ENUM) (defaults to: nil)

    An enum value representing where this document is along its processing lifecycle. Note that this is different than its indexing lifecycle.

    • ‘QUEUED` - Queued

    • ‘PROCESSING` - Processing

    • ‘PROCESSED` - Processed

    • ‘FAILED` - Failed

  • processing_failure_reason (PROCESSING_FAILURE_REASON_ENUM) (defaults to: nil)

    An enum value representing why the document could not be processed. Is null unless processing_state is FAILED.

    • ‘EXCEEDED_CHARACTER_LIMIT` - Exceeded Character Limit

    • ‘INVALID_FILE` - Invalid File

  • status (DOCUMENT_STATUS) (defaults to: nil)

    The document’s current status.

    • ‘ACTIVE` - Active

  • keywords (Array<String>) (defaults to: nil)

    A list of keywords associated with this document. Originally provided when uploading the document.

  • metadata (Hash{String => String}) (defaults to: nil)

    A previously supplied JSON object containing metadata that can be filtered on when searching.

  • document_to_document_indexes (Array<DocumentDocumentToDocumentIndex>)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vellum_ai/types/slim_document.rb', line 34

def initialize(id:, last_uploaded_at:, label:, document_to_document_indexes:, external_id: nil, processing_state: nil,
               processing_failure_reason: nil, status: nil, keywords: nil, metadata: nil, additional_properties: nil)
  # @type [String] Vellum-generated ID that uniquely identifies this document.
  @id = id
  # @type [String] The external ID that was originally provided when uploading the document.
  @external_id = external_id
  # @type [DateTime] A timestamp representing when this document was most recently uploaded.
  @last_uploaded_at = last_uploaded_at
  # @type [String] Human-friendly name for this document.
  @label = label
  # @type [PROCESSING_STATE_ENUM] An enum value representing where this document is along its processing lifecycle. Note that this is different than its indexing lifecycle.
  #   - `QUEUED` - Queued
  #   - `PROCESSING` - Processing
  #   - `PROCESSED` - Processed
  #   - `FAILED` - Failed
  @processing_state = processing_state
  # @type [PROCESSING_FAILURE_REASON_ENUM] An enum value representing why the document could not be processed. Is null unless processing_state is FAILED.
  #   - `EXCEEDED_CHARACTER_LIMIT` - Exceeded Character Limit
  #   - `INVALID_FILE` - Invalid File
  @processing_failure_reason = processing_failure_reason
  # @type [DOCUMENT_STATUS] The document's current status.
  #   - `ACTIVE` - Active
  @status = status
  # @type [Array<String>] A list of keywords associated with this document. Originally provided when uploading the document.
  @keywords = keywords
  # @type [Hash{String => String}] A previously supplied JSON object containing metadata that can be filtered on when searching.
  @metadata = 
  # @type [Array<DocumentDocumentToDocumentIndex>]
  @document_to_document_indexes = document_to_document_indexes
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def additional_properties
  @additional_properties
end

#document_to_document_indexesObject (readonly)

Returns the value of attribute document_to_document_indexes.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def document_to_document_indexes
  @document_to_document_indexes
end

#external_idObject (readonly)

Returns the value of attribute external_id.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def external_id
  @external_id
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def id
  @id
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def keywords
  @keywords
end

#labelObject (readonly)

Returns the value of attribute label.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def label
  @label
end

#last_uploaded_atObject (readonly)

Returns the value of attribute last_uploaded_at.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def last_uploaded_at
  @last_uploaded_at
end

#metadataObject (readonly)

Returns the value of attribute metadata.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def 
  @metadata
end

#processing_failure_reasonObject (readonly)

Returns the value of attribute processing_failure_reason.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def processing_failure_reason
  @processing_failure_reason
end

#processing_stateObject (readonly)

Returns the value of attribute processing_state.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def processing_state
  @processing_state
end

#statusObject (readonly)

Returns the value of attribute status.



12
13
14
# File 'lib/vellum_ai/types/slim_document.rb', line 12

def status
  @status
end

Class Method Details

.from_json(json_object:) ⇒ SlimDocument

Deserialize a JSON object to an instance of SlimDocument

Parameters:

  • json_object (JSON)

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/vellum_ai/types/slim_document.rb', line 71

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = struct.id
  external_id = struct.external_id
  last_uploaded_at = DateTime.parse(parsed_json["last_uploaded_at"])
  label = struct.label
  processing_state = PROCESSING_STATE_ENUM.key(parsed_json["processing_state"]) || parsed_json["processing_state"]
  processing_failure_reason = PROCESSING_FAILURE_REASON_ENUM.key(parsed_json["processing_failure_reason"]) || parsed_json["processing_failure_reason"]
  status = struct.status
  keywords = struct.keywords
   = struct.
  document_to_document_indexes = parsed_json["document_to_document_indexes"].map do |v|
    v = v.to_json
    DocumentDocumentToDocumentIndex.from_json(json_object: v)
  end
  new(id: id, external_id: external_id, last_uploaded_at: last_uploaded_at, label: label,
      processing_state: processing_state, processing_failure_reason: processing_failure_reason, status: status, keywords: keywords, metadata: , document_to_document_indexes: document_to_document_indexes, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/vellum_ai/types/slim_document.rb', line 113

def self.validate_raw(obj:)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.external_id&.is_a?(String) != false || raise("Passed value for field obj.external_id is not the expected type, validation failed.")
  obj.last_uploaded_at.is_a?(DateTime) != false || raise("Passed value for field obj.last_uploaded_at is not the expected type, validation failed.")
  obj.label.is_a?(String) != false || raise("Passed value for field obj.label is not the expected type, validation failed.")
  obj.processing_state&.is_a?(PROCESSING_STATE_ENUM) != false || raise("Passed value for field obj.processing_state is not the expected type, validation failed.")
  obj.processing_failure_reason&.is_a?(PROCESSING_FAILURE_REASON_ENUM) != false || raise("Passed value for field obj.processing_failure_reason is not the expected type, validation failed.")
  obj.status&.is_a?(String) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
  obj.keywords&.is_a?(Array) != false || raise("Passed value for field obj.keywords is not the expected type, validation failed.")
  obj.&.is_a?(Hash) != false || raise("Passed value for field obj.metadata is not the expected type, validation failed.")
  obj.document_to_document_indexes.is_a?(Array) != false || raise("Passed value for field obj.document_to_document_indexes is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of SlimDocument to a JSON object

Returns:

  • (JSON)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/vellum_ai/types/slim_document.rb', line 94

def to_json(*_args)
  {
    "id": @id,
    "external_id": @external_id,
    "last_uploaded_at": @last_uploaded_at,
    "label": @label,
    "processing_state": PROCESSING_STATE_ENUM[@processing_state] || @processing_state,
    "processing_failure_reason": PROCESSING_FAILURE_REASON_ENUM[@processing_failure_reason] || @processing_failure_reason,
    "status": @status,
    "keywords": @keywords,
    "metadata": @metadata,
    "document_to_document_indexes": @document_to_document_indexes
  }.to_json
end