omniai 2.8.4 → 2.9.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: 533dd085c62bb70b08d71d16025423b981d96cbffe7a1280072908f175800d28
4
- data.tar.gz: c40684be74123a132c11ecc70a620ee49d4b6e949daf08f91c8f5a360d0ea56f
3
+ metadata.gz: 7f355f49e0fcac63485f6e017ae90eb6f499cd1223cb4ec125422cdef08e14cb
4
+ data.tar.gz: f07aca376c9982b6f9b071ab426e775c73bc8a20a04d6d4aa2aa5a50b3edd0be
5
5
  SHA512:
6
- metadata.gz: 355abe067bdc6a6156300ea305b441a14388239506565a753f12dfc7824fe2d1a7acee4772fe8556fec5dbee2a9a3a9e25506ddb9faa7d78d3838bf647d17424
7
- data.tar.gz: 03d292f24d8345c4f4043f185b4c5e01ce09894afc7e9cd72e81f251cd9c394c8af2165f2c054bcb0cff60f50f75498efb90f4eb79e724e829b86561420819ff
6
+ metadata.gz: 7a6d2bdd83346d8c1b5a66d9351d2e11ede416901b276c85b3ff2f3997c390cff566ced9a1f841df5639347fe6f0f9f6b4586b97d8e9cfcf88d91c5f02d8c086
7
+ data.tar.gz: 770012e9af20274e3f64f89819695cc918f1d3f827137244e76604f37bc5510f58a7ac2ca8a66a16336a3d6448230e0deb61f2c90e36f2bff1d867043f3bc702
@@ -15,6 +15,8 @@ module OmniAI
15
15
  # })
16
16
  # format.serialize # => { name: "example", schema: { ... } }
17
17
  class Format
18
+ BLOCK_REGEX = /```(?:json)?\s*(?<text>.+)\s*```/m
19
+
18
20
  # @!attribute [rw] name
19
21
  # @return [String]
20
22
  attr_accessor :name
@@ -66,10 +68,29 @@ module OmniAI
66
68
  #
67
69
  # @return [Hash]
68
70
  def parse(text)
71
+ match = BLOCK_REGEX.match(text)
72
+ text = match[:text] if match
73
+
69
74
  schema.parse(JSON.parse(text))
70
75
  rescue JSON::ParserError => e
71
76
  raise OmniAI::ParseError, "Unable to parse JSON text=#{text.inspect} message=#{e.message.inspect}."
72
77
  end
78
+
79
+ # A helper used for LLMs that do not support passing in a schema using a dedicated argument.
80
+ #
81
+ # @example
82
+ # format.prompt #=> "Your response must match the following schema: ..."
83
+ #
84
+ # @return [String]
85
+ def prompt
86
+ <<~TEXT
87
+ Your must respond with ONLY valid JSON matching this exact schema:
88
+
89
+ #{JSON.generate(schema.serialize)}
90
+
91
+ Do not include any preamble, explanation, heredocs, etc. Return only the JSON.
92
+ TEXT
93
+ end
73
94
  end
74
95
  end
75
96
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = "2.8.4"
4
+ VERSION = "2.9.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.4
4
+ version: 2.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre