Class: OmniAI::Mistral::OCR
- Inherits:
-
Object
- Object
- OmniAI::Mistral::OCR
- Defined in:
- lib/omniai/mistral/ocr.rb,
lib/omniai/mistral/ocr/page.rb,
lib/omniai/mistral/ocr/image.rb,
lib/omniai/mistral/ocr/response.rb,
lib/omniai/mistral/ocr/dimensions.rb
Overview
An implementation of the OCR API.
Defined Under Namespace
Modules: Kind, Model Classes: Dimensions, Image, Page, Response
Constant Summary collapse
- VERSION =
"v1"
- DEFAULT_KIND =
Kind::DOCUMENT
- DEFAULT_MODEL =
Model::OCR_LATEST
Class Method Summary collapse
Instance Method Summary collapse
- #document! ⇒ Hash
-
#initialize(document, client:, kind: DEFAULT_KIND, model: DEFAULT_MODEL, options: {}) ⇒ OCR
constructor
A new instance of OCR.
- #process! ⇒ Response
Constructor Details
#initialize(document, client:, kind: DEFAULT_KIND, model: DEFAULT_MODEL, options: {}) ⇒ OCR
Returns a new instance of OCR.
39 40 41 42 43 44 45 |
# File 'lib/omniai/mistral/ocr.rb', line 39 def initialize(document, client:, kind: DEFAULT_KIND, model: DEFAULT_MODEL, options: {}) @document = document @client = client @options = @kind = kind @model = model end |
Class Method Details
.process!(document, client:, kind: DEFAULT_KIND, model: DEFAULT_MODEL, options: {}) ⇒ Response
30 31 32 |
# File 'lib/omniai/mistral/ocr.rb', line 30 def self.process!(document, client:, kind: DEFAULT_KIND, model: DEFAULT_MODEL, options: {}) new(document, client:, kind:, model:, options:).process! end |
Instance Method Details
#document! ⇒ Hash
62 63 64 65 66 67 |
# File 'lib/omniai/mistral/ocr.rb', line 62 def document! case @kind when Kind::DOCUMENT then { document_url: @document, type: "document_url" } when Kind::IMAGE then { image_url: @document, type: "image_url" } end end |
#process! ⇒ Response
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/omniai/mistral/ocr.rb', line 50 def process! response = @client.connection.accept(:json).post("/#{VERSION}/ocr", json: @options.merge({ model: @model, document: document!, }).compact) raise HTTPError, response.flush unless response.status.ok? Response.parse(data: response.parse) end |