Class: GroqRuby::Resources::Files

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#initialize

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.

Parameters:

  • file_id (String)

Returns:

  • (String)

    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.

Parameters:

  • file (IO, File)

    readable IO whose ‘#read` returns the bytes.

  • filename (String)

    name to send with the multipart upload.

  • purpose (String)

    currently always ‘“batch”`.

Returns:

Raises:



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

Parameters:

  • file_id (String)

Returns:



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

Parameters:

  • file_id (String)

Returns:



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

#listGroqRuby::Models::FileList



32
33
34
# File 'lib/groq_ruby/resources/files.rb', line 32

def list
  GroqRuby::Models::FileList.from_hash(perform(Request.new(method: :get, path: BASE_PATH)))
end