Class: GroqRuby::Resources::Files
- Defined in:
- lib/groq_ruby/resources/files.rb
Overview
‘client.files.*` — upload, list, fetch, and delete files used by the batch endpoints.
Constant Summary collapse
- BASE_PATH =
"/openai/v1/files".freeze
- CREATE_SCHEMA =
Dry::Schema.define do required(:purpose).filled(:string, included_in?: %w[batch]) end
Instance Method Summary collapse
-
#content(file_id) ⇒ String
The raw bytes of the file.
-
#create(file:, filename:, purpose:) ⇒ GroqRuby::Models::FileObject
Upload a JSONL file to be referenced from a batch job.
- #delete(file_id) ⇒ GroqRuby::Models::FileDeleted
- #info(file_id) ⇒ GroqRuby::Models::FileObject
- #list ⇒ GroqRuby::Models::FileList
Methods inherited from Base
Constructor Details
This class inherits a constructor from GroqRuby::Resources::Base
Instance Method Details
#content(file_id) ⇒ String
Returns the raw bytes of the file.
44 45 46 |
# File 'lib/groq_ruby/resources/files.rb', line 44 def content(file_id) perform(Request.new(method: :get, path: "#{BASE_PATH}/#{file_id}/content"), accept: :binary) end |
#create(file:, filename:, purpose:) ⇒ GroqRuby::Models::FileObject
Upload a JSONL file to be referenced from a batch job.
21 22 23 24 25 26 27 28 29 |
# File 'lib/groq_ruby/resources/files.rb', line 21 def create(file:, filename:, purpose:) validate!(CREATE_SCHEMA, {purpose: purpose}) multipart = Multipart.new([ Multipart::Part.text("purpose", purpose), Multipart::Part.file("file", io: file, filename: filename, content_type: "application/jsonl") ]) request = Request.new(method: :post, path: BASE_PATH, body: multipart.body, content_type: multipart.content_type) GroqRuby::Models::FileObject.from_hash(perform(request)) end |
#delete(file_id) ⇒ GroqRuby::Models::FileDeleted
50 51 52 |
# File 'lib/groq_ruby/resources/files.rb', line 50 def delete(file_id) GroqRuby::Models::FileDeleted.from_hash(perform(Request.new(method: :delete, path: "#{BASE_PATH}/#{file_id}"))) end |
#info(file_id) ⇒ GroqRuby::Models::FileObject
38 39 40 |
# File 'lib/groq_ruby/resources/files.rb', line 38 def info(file_id) GroqRuby::Models::FileObject.from_hash(perform(Request.new(method: :get, path: "#{BASE_PATH}/#{file_id}"))) end |