Class: ContextDev::Resources::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/context_dev/resources/parse.rb,
sig/context_dev/resources/parse.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Parse

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 Parse.

Parameters:



54
55
56
# File 'lib/context_dev/resources/parse.rb', line 54

def initialize(client:)
  @client = client
end

Instance Method Details

#handle(body:, extension: nil, include_images: nil, include_links: nil, ocr: nil, pdf: nil, shorten_base64_images: nil, use_main_content_only: nil, request_options: {}) ⇒ ContextDev::Models::ParseHandleResponse

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

Converts raw text, source code, web/data, PDF, Microsoft Office, and image bytes into LLM-usable Markdown. The base request costs 1 credit. When OCR runs (requires ocr=true), the entire call costs 5 credits; ocr=true requests where no OCR ends up running still cost 1 credit.

Parameters:

  • body (Pathname, StringIO, IO, String, ContextDev::FilePart)

    Body param

  • extension (Symbol, ContextDev::Models::ParseHandleParams::Extension)

    Query param: Optional file extension hint. Case-insensitive; a leading dot is ac

  • include_images (Boolean)

    Query param: Include image references in Markdown output

  • include_links (Boolean)

    Query param: Preserve hyperlinks in Markdown output

  • ocr (Boolean)

    Query param: Gates all OCR. When true, PDFs get embedded-image OCR (recognized t

  • pdf (ContextDev::Models::ParseHandleParams::Pdf)

    Query param: PDF page-range controls. Use start/end to limit parsing (and OCR wh

  • shorten_base64_images (Boolean)

    Query param: Shorten base64-encoded image data in the Markdown output

  • use_main_content_only (Boolean)

    Query param: Extract only the main content from HTML-like inputs

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

Returns:

See Also:



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/context_dev/resources/parse.rb', line 37

def handle(params)
  parsed, options = ContextDev::ParseHandleParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed.except(:body))
  @client.request(
    method: :post,
    path: "parse",
    query: query,
    headers: {"content-type" => "application/octet-stream"},
    body: parsed[:body],
    model: ContextDev::Models::ParseHandleResponse,
    options: options
  )
end