Class: OmniAI::OpenAI::File
- Inherits:
-
Object
- Object
- OmniAI::OpenAI::File
- Defined in:
- lib/omniai/openai/file.rb
Overview
An OpenAI file implementation.
Defined Under Namespace
Modules: Purpose
Instance Attribute Summary collapse
Class Method Summary collapse
- .all(client: Client.new) ⇒ Array<OmniAI::OpenAI::File>
- .destroy!(id:, client: Client.new) ⇒ Hash
- .find(id:, client: Client.new) ⇒ OmniAI::OpenAI::Assistant
Instance Method Summary collapse
- #content {|String| ... } ⇒ Object
- #destroy! ⇒ OmniAI::OpenAI::Assistant
-
#initialize(client: Client.new, io: nil, id: nil, bytes: nil, filename: nil, purpose: Purpose::ASSISTANTS) ⇒ File
constructor
A new instance of File.
- #inspect ⇒ String
- #save! ⇒ OmniAI::OpenAI::Assistant
Constructor Details
#initialize(client: Client.new, io: nil, id: nil, bytes: nil, filename: nil, purpose: Purpose::ASSISTANTS) ⇒ File
Returns a new instance of File.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/omniai/openai/file.rb', line 37 def initialize( client: Client.new, io: nil, id: nil, bytes: nil, filename: nil, purpose: Purpose::ASSISTANTS ) @client = client @io = io @id = id @bytes = bytes @filename = filename @purpose = purpose end |
Instance Attribute Details
#bytes ⇒ Integer?
13 14 15 |
# File 'lib/omniai/openai/file.rb', line 13 def bytes @bytes end |
#deleted ⇒ Boolean?
25 26 27 |
# File 'lib/omniai/openai/file.rb', line 25 def deleted @deleted end |
#filename ⇒ String?
17 18 19 |
# File 'lib/omniai/openai/file.rb', line 17 def filename @filename end |
#id ⇒ String?
9 10 11 |
# File 'lib/omniai/openai/file.rb', line 9 def id @id end |
#purpose ⇒ String?
21 22 23 |
# File 'lib/omniai/openai/file.rb', line 21 def purpose @purpose end |
Class Method Details
.all(client: Client.new) ⇒ Array<OmniAI::OpenAI::File>
86 87 88 89 90 91 92 93 94 |
# File 'lib/omniai/openai/file.rb', line 86 def self.all(client: Client.new) response = client.connection .accept(:json) .get("/#{OmniAI::OpenAI::Client::VERSION}/files") raise HTTPError, response.flush unless response.status.ok? response.parse['data'].map { |data| parse(data:, client:) } end |
.destroy!(id:, client: Client.new) ⇒ Hash
99 100 101 102 103 104 105 106 107 |
# File 'lib/omniai/openai/file.rb', line 99 def self.destroy!(id:, client: Client.new) response = client.connection .accept(:json) .delete("/#{OmniAI::OpenAI::Client::VERSION}/files/#{id}") raise HTTPError, response.flush unless response.status.ok? response.parse end |
.find(id:, client: Client.new) ⇒ OmniAI::OpenAI::Assistant
74 75 76 77 78 79 80 81 82 |
# File 'lib/omniai/openai/file.rb', line 74 def self.find(id:, client: Client.new) response = client.connection .accept(:json) .get("/#{OmniAI::OpenAI::Client::VERSION}/files/#{id}") raise HTTPError, response.flush unless response.status.ok? parse(data: response.parse) end |
Instance Method Details
#content {|String| ... } ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/omniai/openai/file.rb', line 60 def content(&) raise OmniAI::Error, 'cannot fetch content without ID' unless @id response = @client.connection .get("/#{OmniAI::OpenAI::Client::VERSION}/files/#{@id}/content") raise HTTPError, response.flush unless response.status.ok? response.body.each(&) end |
#destroy! ⇒ OmniAI::OpenAI::Assistant
125 126 127 128 129 130 131 |
# File 'lib/omniai/openai/file.rb', line 125 def destroy! raise OmniAI::Error, 'cannot destroy w/o ID' unless @id data = self.class.destroy!(id: @id, client: @client) @deleted = data['deleted'] self end |
#inspect ⇒ String
54 55 56 |
# File 'lib/omniai/openai/file.rb', line 54 def inspect "#<#{self.class.name} id=#{@id.inspect} filename=#{@filename.inspect}>" end |
#save! ⇒ OmniAI::OpenAI::Assistant
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/omniai/openai/file.rb', line 111 def save! raise OmniAI::Error, 'cannot save a file without IO' unless @io response = @client.connection .accept(:json) .post("/#{OmniAI::OpenAI::Client::VERSION}/files", form: payload) raise HTTPError, response.flush unless response.status.ok? parse(data: response.parse) self end |