omniai-mistral 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29008395f4e0da0a72899f2ddb6817f727a1a2c5be46063aa6693043164bcfcf
4
- data.tar.gz: 92a5bd8542912d968aecb7d13d1d64080144d8d20a0b53cd47fd8f757a060fb7
3
+ metadata.gz: 360410f4a0d40370818852aafbb3d7d8680d8758b30e42e9c00d2b0d2f3508fb
4
+ data.tar.gz: 115604d511fe504e8cd88ff0f846e811d8f6d3e2da69258fd029654bf737f277
5
5
  SHA512:
6
- metadata.gz: 14faceab19d119a03fee9b6226b25569c0cbea0a6b3bb680ea47db5d4c483487e45a0c8e91f6415a49583a7a0ec6a0836a3817d4265dcc4998bf2f795bc8a106
7
- data.tar.gz: 7fb98a39c2e34db5ee12f62dd794d7f7ffb33d5b1bcb0099fdb5fcc3d3b36096d2972eb9061d033bdf969276d1ec7d573bda89184bc2a8180d8aa1e85d52d874
6
+ metadata.gz: efe4e899a3b518133788cb9385db9e24cdd7e269223e686cf118ad4e775b61000f1a7a97a9c380653c8f511f8624970c89fecca240f10e3eae0d7c507b5603c3
7
+ data.tar.gz: 90f89f6856daeff1974ccea7f4858affa6c501f3011e9a3a1a16ff59948f025b97a50e2c6b92e01b18891c91b4ad5868303f3e5c82124f9bf35df06c775bf200
@@ -54,7 +54,7 @@ module OmniAI
54
54
  # @yield [prompt] optional
55
55
  # @yieldparam prompt [OmniAI::Chat::Prompt]
56
56
  #
57
- # @return [OmniAI::Chat::Completion]
57
+ # @return [OmniAI::Chat::Response]
58
58
  def chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil, &)
59
59
  Chat.process!(messages, model:, temperature:, format:, stream:, tools:, client: self, &)
60
60
  end
@@ -63,9 +63,25 @@ module OmniAI
63
63
  #
64
64
  # @param input [String, Array<String>, Array<Integer>] required
65
65
  # @param model [String] optional
66
+ #
67
+ # @return [OmniAI::Embed::Response]
66
68
  def embed(input, model: Embed::DEFAULT_MODEL)
67
69
  Embed.process!(input, model:, client: self)
68
70
  end
71
+
72
+ # @raise [OmniAI::Error]
73
+ #
74
+ # @param document [String] e.g. "https://vancouver.ca/files/cov/other-sectors-tourism.PDF"
75
+ # @param kind [Symbol] optional - `:document` or `:image` - default = `:document``
76
+ # @param model [String] optional - default = "mistral-ocr-latest"
77
+ # @param options [Hash] optional - e.g. `{ image_limit: 4 }`
78
+ #
79
+ # @raise [OmniAI::Error]
80
+ #
81
+ # @return [OmniAI::Mistral::OCR::Response]
82
+ def ocr(document, kind: OCR::DEFAULT_KIND, model: OCR::DEFAULT_MODEL, options: {})
83
+ OCR.process!(document, kind:, model:, options:, client: self)
84
+ end
69
85
  end
70
86
  end
71
87
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module Mistral
5
+ class OCR
6
+ # Dimensions returned by the OCR API.
7
+ class Dimensions
8
+ # !@attribute [rw] width
9
+ # @return [Integer]
10
+ attr_accessor :width
11
+
12
+ # !@attribute [rw] height
13
+ # @return [Integer]
14
+ attr_accessor :height
15
+
16
+ # !@attribute [rw] dpi
17
+ # @return [Integer]
18
+ attr_accessor :dpi
19
+
20
+ # @param width [Integer]
21
+ # @param height [Integer]
22
+ # @param dpi [Integer]
23
+ def initialize(width:, height:, dpi:)
24
+ @width = width
25
+ @height = height
26
+ @dpi = dpi
27
+ end
28
+
29
+ # @param data [Hash]
30
+ #
31
+ # @return [Dimensions]
32
+ def self.parse(data:)
33
+ new(width: data["width"], height: data["height"], dpi: data["dpi"])
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module Mistral
5
+ class OCR
6
+ # An image returned by the OCR API.
7
+ class Image
8
+ # !@attribute [rw] id
9
+ # @return [Integer]
10
+ attr_accessor :id
11
+
12
+ # !@attribute [rw] top_left_x
13
+ # @return [Integer]
14
+ attr_accessor :top_left_x
15
+
16
+ # !@attribute [rw] top_left_y
17
+ # @return [Integer]
18
+ attr_accessor :top_left_y
19
+
20
+ # !@attribute [rw] bottom_right_x
21
+ # @return [Integer]
22
+ attr_accessor :bottom_right_x
23
+
24
+ # !@attribute [rw] bottom_right_y
25
+ # @return [Integer]
26
+ attr_accessor :bottom_right_y
27
+
28
+ # !@attribute [rw] image_base64
29
+ # @return [String]
30
+ attr_accessor :image_base64
31
+
32
+ # @param id [Integer]
33
+ # @param top_left_x [Integer]
34
+ # @param top_left_y [Integer]
35
+ # @param bottom_right_x [Integer]
36
+ # @param bottom_right_y [Integer]
37
+ # @param image_base64 [String]
38
+ def initialize(id:, top_left_x:, top_left_y:, bottom_right_x:, bottom_right_y:, image_base64:)
39
+ @id = id
40
+ @top_left_x = top_left_x
41
+ @top_left_y = top_left_y
42
+ @bottom_right_x = bottom_right_x
43
+ @bottom_right_y = bottom_right_y
44
+ @image_base64 = image_base64
45
+ end
46
+
47
+ # @param data [Hash]
48
+ #
49
+ # @return [Image]
50
+ def self.parse(data:)
51
+ new(
52
+ id: data["id"],
53
+ top_left_x: data["top_left_x"],
54
+ top_left_y: data["top_left_y"],
55
+ bottom_right_x: data["bottom_right_x"],
56
+ bottom_right_y: data["bottom_right_y"],
57
+ image_base64: data["image_base64"]
58
+ )
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module Mistral
5
+ class OCR
6
+ # A page returned by the OCR API.
7
+ class Page
8
+ # !@attribute [rw] index
9
+ # @return [Integer]
10
+ attr_accessor :index
11
+
12
+ # !@attribute [rw] markdown
13
+ # @return [String]
14
+ attr_accessor :markdown
15
+
16
+ # !@attribute [rw] images
17
+ # @return [Array<Image>]
18
+ attr_accessor :images
19
+
20
+ # !@attribute [rw] dimensions
21
+ # @return [Dimensions]
22
+ attr_accessor :dimensions
23
+
24
+ # @param index [Integer]
25
+ # @param markdown [String]
26
+ # @param images [Array<Image>]
27
+ # @param dimensions [Dimensions]
28
+ def initialize(index:, markdown:, images:, dimensions:)
29
+ @index = index
30
+ @markdown = markdown
31
+ @images = images
32
+ @dimensions = dimensions
33
+ end
34
+
35
+ # @param data [Hash]
36
+ #
37
+ # @return [Page]
38
+ def self.parse(data:)
39
+ new(
40
+ index: data["index"],
41
+ markdown: data["markdown"],
42
+ images: data["images"].map { |image_data| Image.parse(data: image_data) },
43
+ dimensions: Dimensions.parse(data: data["dimensions"])
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module Mistral
5
+ class OCR
6
+ # The response from the OCR API.
7
+ class Response
8
+ # !@attribute [rw] model
9
+ # @return [Array<Model>]
10
+ attr_accessor :model
11
+
12
+ # !@attribute [rw] pages
13
+ # @return [Array<Page>]
14
+ attr_accessor :pages
15
+
16
+ # @param model [String]
17
+ # @param pages [Array<Page>]
18
+ def initialize(model:, pages:)
19
+ @model = model
20
+ @pages = pages
21
+ end
22
+
23
+ # @param data [Hash]
24
+ #
25
+ # @return [Response]
26
+ def self.parse(data:)
27
+ new(model: data["model"], pages: data["pages"].map { |page| Page.parse(data: page) })
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module Mistral
5
+ # An implementation of the OCR API.
6
+ class OCR
7
+ VERSION = "v1"
8
+
9
+ module Kind
10
+ DOCUMENT = :document
11
+ IMAGE = :image
12
+ end
13
+
14
+ module Model
15
+ OCR_LATEST = "mistral-ocr-latest"
16
+ end
17
+
18
+ DEFAULT_KIND = Kind::DOCUMENT
19
+ DEFAULT_MODEL = Model::OCR_LATEST
20
+
21
+ # @raise [Error]
22
+ #
23
+ # @param client [OmniAI::Mistral::Client]
24
+ # @param document [String] a URL
25
+ # @param kind [Symbol] optional
26
+ # @param model [String] optional
27
+ # @param options [Hash] optional (e.g. `{ image_limit: 4 }`)
28
+ #
29
+ # @return [Response]
30
+ def self.process!(document, client:, kind: DEFAULT_KIND, model: DEFAULT_MODEL, options: {})
31
+ new(document, client:, kind:, model:, options:).process!
32
+ end
33
+
34
+ # @param client [OmniAI::Mistral::Client]
35
+ # @param document [String] a URL
36
+ # @param kind [Symbol] optional
37
+ # @param model [String] optional
38
+ # @param options [Hash] optional (e.g. `{ image_limit: 4 }`)
39
+ def initialize(document, client:, kind: DEFAULT_KIND, model: DEFAULT_MODEL, options: {})
40
+ @document = document
41
+ @client = client
42
+ @options = options
43
+ @kind = kind
44
+ @model = model
45
+ end
46
+
47
+ # @raise [Error]
48
+ #
49
+ # @return [Response]
50
+ def process!
51
+ response = @client.connection.accept(:json).post("/#{VERSION}/ocr", json: @options.merge({
52
+ model: @model,
53
+ document: document!,
54
+ }).compact)
55
+
56
+ raise HTTPError, response.flush unless response.status.ok?
57
+
58
+ Response.parse(data: response.parse)
59
+ end
60
+
61
+ # @return [Hash]
62
+ def document!
63
+ case @kind
64
+ when Kind::DOCUMENT then { document_url: @document, type: "document_url" }
65
+ when Kind::IMAGE then { image_url: @document, type: "image_url" }
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Mistral
5
- VERSION = "2.0.0"
5
+ VERSION = "2.0.1"
6
6
  end
7
7
  end
@@ -6,6 +6,7 @@ require "zeitwerk"
6
6
 
7
7
  loader = Zeitwerk::Loader.for_gem
8
8
  loader.push_dir(__dir__, namespace: OmniAI)
9
+ loader.inflector.inflect "ocr" => "OCR"
9
10
  loader.setup
10
11
 
11
12
  module OmniAI
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-mistral
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-03 00:00:00.000000000 Z
10
+ date: 2025-03-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: event_stream_parser
@@ -65,6 +65,11 @@ files:
65
65
  - lib/omniai/mistral/client.rb
66
66
  - lib/omniai/mistral/config.rb
67
67
  - lib/omniai/mistral/embed.rb
68
+ - lib/omniai/mistral/ocr.rb
69
+ - lib/omniai/mistral/ocr/dimensions.rb
70
+ - lib/omniai/mistral/ocr/image.rb
71
+ - lib/omniai/mistral/ocr/page.rb
72
+ - lib/omniai/mistral/ocr/response.rb
68
73
  - lib/omniai/mistral/version.rb
69
74
  homepage: https://github.com/ksylvest/omniai-mistral
70
75
  licenses: