Class: OpenAI::Resources::Files

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/resources/files.rb

Overview

Files are used to upload documents that can be used with features like Assistants and Fine-tuning.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Files

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 a new instance of Files.

Parameters:



154
155
156
# File 'lib/openai/resources/files.rb', line 154

def initialize(client:)
  @client = client
end

Instance Method Details

#content(file_id, request_options: {}) ⇒ StringIO

Returns the contents of the specified file.

Parameters:

  • file_id (String)

    The ID of the file to use for this request.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (StringIO)

See Also:



141
142
143
144
145
146
147
148
149
# File 'lib/openai/resources/files.rb', line 141

def content(file_id, params = {})
  @client.request(
    method: :get,
    path: ["files/%1$s/content", file_id],
    headers: {"accept" => "application/binary"},
    model: StringIO,
    options: params[:request_options]
  )
end

#create(file:, purpose:, expires_after: nil, request_options: {}) ⇒ OpenAI::Models::FileObject

Some parameter documentations has been truncated, see Models::FileCreateParams for more details.

Upload a file that can be used across various endpoints. Individual files can be up to 512 MB, and each project can store up to 2.5 TB of files in total. There is no organization-wide storage limit.

Please [contact us](help.openai.com/) if you need to increase these storage limits.

Parameters:

Returns:

See Also:



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/openai/resources/files.rb', line 45

def create(params)
  parsed, options = OpenAI::FileCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "files",
    headers: {"content-type" => "multipart/form-data"},
    body: parsed,
    model: OpenAI::FileObject,
    options: options
  )
end

#delete(file_id, request_options: {}) ⇒ OpenAI::Models::FileDeleted

Delete a file and remove it from all vector stores.

Parameters:

  • file_id (String)

    The ID of the file to use for this request.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



121
122
123
124
125
126
127
128
# File 'lib/openai/resources/files.rb', line 121

def delete(file_id, params = {})
  @client.request(
    method: :delete,
    path: ["files/%1$s", file_id],
    model: OpenAI::FileDeleted,
    options: params[:request_options]
  )
end

#list(after: nil, limit: nil, order: nil, purpose: nil, request_options: {}) ⇒ OpenAI::Internal::CursorPage<OpenAI::Models::FileObject>

Some parameter documentations has been truncated, see Models::FileListParams for more details.

Returns a list of files.

Parameters:

  • after (String)

    A cursor for use in pagination. after is an object ID that defines your place

  • limit (Integer)

    A limit on the number of objects to be returned. Limit can range between 1 and 1

  • order (Symbol, OpenAI::Models::FileListParams::Order)

    Sort order by the created_at timestamp of the objects. asc for ascending ord

  • purpose (String)

    Only return files with the given purpose.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/openai/resources/files.rb', line 97

def list(params = {})
  parsed, options = OpenAI::FileListParams.dump_request(params)
  query = OpenAI::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "files",
    query: query,
    page: OpenAI::Internal::CursorPage,
    model: OpenAI::FileObject,
    options: options
  )
end

#retrieve(file_id, request_options: {}) ⇒ OpenAI::Models::FileObject

Returns information about a specific file.

Parameters:

  • file_id (String)

    The ID of the file to use for this request.

  • request_options (OpenAI::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



68
69
70
71
72
73
74
75
# File 'lib/openai/resources/files.rb', line 68

def retrieve(file_id, params = {})
  @client.request(
    method: :get,
    path: ["files/%1$s", file_id],
    model: OpenAI::FileObject,
    options: params[:request_options]
  )
end