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:



58
59
60
# File 'lib/context_dev/resources/parse.rb', line 58

def initialize(client:)
  @client = client
end

Instance Method Details

#handle(body:, client: nil, extension: nil, include_images: nil, include_links: nil, ocr: nil, pdf: nil, shorten_base64_images: nil, tags: nil, use_main_content_only: nil, zdr: 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.

Parameters:

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

    Body param

  • client (String)

    Query param: Optional client identifier used for usage attribution.

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

    Query param: Optional file extension hint, such as pdf, docx, xlsx, pptx, html,

  • 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: When true for PDF inputs, OCR the selected pages that have no usabl

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

    Query param: PDF page-range options as a JSON object, e.g. {"start": 2, "end": 5

  • shorten_base64_images (Boolean)

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

  • tags (Array<String>)

    Query param: Optional comma-separated caller-defined tags for tracking this requ

  • use_main_content_only (Boolean)

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

  • zdr (Symbol, ContextDev::Models::ParseHandleParams::Zdr)

    Query param: Set to enabled to bypass shared caches and omit request and respons

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

Returns:

See Also:



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/context_dev/resources/parse.rb', line 41

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