llm.rb 4.16.0 → 4.16.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: 793403110075dfcc650d4b0931ebcdfee74787ce1412b61318d7d749b22c3e9f
4
- data.tar.gz: 469e1b635896822483e8a6ec7cebaf8c34443b90010435c4ae2d4899fd71c1b4
3
+ metadata.gz: 6119e0673d055f50139fd33a4523bd99ffabb0fc2688a361f23297ef9ac428fd
4
+ data.tar.gz: bfa5943241a2e9944245f0976458cfdd4895e7b72dbb83fd186f9d7ad2b987ee
5
5
  SHA512:
6
- metadata.gz: 515e571ad97704659363a764f633c9199239d0ad1e741b1239e7528cf455160a1246ba756fa16201c47f03b5185939809842eef28aaeb45123aa38c038c23232
7
- data.tar.gz: 180e987e00885e15d004965e98c5b70b00481568be43c168431afaad27baed40adfb8c93a9cad10fb96210dad3e768407524422b5edf0c62b011ef57900ac742
6
+ metadata.gz: e139622d5cbaa8f42a1a6739b9792119f9086ae0b11ae896794953d9bb0fa9ed46159da7f10f7a8b619ef468404ae425b2158b359c940a11220dd48b0b230e2e
7
+ data.tar.gz: 563f48928b6836d2bbcbc8d72bd594aa265fa285ad99cb8ff0c9574f9e67b7da60f9d42c2eeb1bddce0ba72e1425dab260bc65670fa7d812f7a77dc8016262d7
data/CHANGELOG.md CHANGED
@@ -2,8 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ Changes since `v4.16.1`.
6
+
7
+ ## v4.16.1
8
+
5
9
  Changes since `v4.16.0`.
6
10
 
11
+ This release tightens ORM persistence by removing an unnecessary JSON
12
+ round-trip when restoring structured `:json` and `:jsonb` context
13
+ payloads.
14
+
15
+ ### Change
16
+
17
+ * **Restore structured ORM payloads directly** <br>
18
+ Teach `LLM::Context#restore` to accept parsed data payloads and use
19
+ that path from the ActiveRecord and Sequel persistence wrappers for
20
+ `format: :json` and `:jsonb`, avoiding a redundant
21
+ `Hash -> JSON string -> Hash` round-trip on restore.
22
+
7
23
  ## v4.16.0
8
24
 
9
25
  Changes since `v4.15.0`.
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  <p align="center">
5
5
  <a href="https://0x1eef.github.io/x/llm.rb?rebuild=1"><img src="https://img.shields.io/badge/docs-0x1eef.github.io-blue.svg" alt="RubyDoc"></a>
6
6
  <a href="https://opensource.org/license/0bsd"><img src="https://img.shields.io/badge/License-0BSD-orange.svg?" alt="License"></a>
7
- <a href="https://github.com/llmrb/llm.rb/tags"><img src="https://img.shields.io/badge/version-4.16.0-green.svg?" alt="Version"></a>
7
+ <a href="https://github.com/llmrb/llm.rb/tags"><img src="https://img.shields.io/badge/version-4.16.1-green.svg?" alt="Version"></a>
8
8
  </p>
9
9
 
10
10
  ## About
@@ -167,12 +167,11 @@ module LLM::ActiveRecord
167
167
  if data.nil? || data == ""
168
168
  ctx
169
169
  else
170
- string = case options[:format]
171
- when :string then data
172
- when :json, :jsonb then LLM.json.dump(data)
170
+ case options[:format]
171
+ when :string then ctx.restore(string: data)
172
+ when :json, :jsonb then ctx.restore(data:)
173
173
  else raise ArgumentError, "Unknown format: #{options[:format].inspect}"
174
174
  end
175
- ctx.restore(string:)
176
175
  end
177
176
  end
178
177
  end
data/lib/llm/context.rb CHANGED
@@ -307,18 +307,21 @@ module LLM
307
307
  # The path to a JSON file
308
308
  # @param [String, nil] string
309
309
  # A raw JSON string
310
+ # @param [Hash, nil] data
311
+ # A parsed context payload
310
312
  # @raise [SystemCallError]
311
313
  # Might raise a number of SystemCallError subclasses
312
314
  # @return [LLM::Context]
313
- def deserialize(path: nil, string: nil)
314
- payload = if path.nil? and string.nil?
315
- raise ArgumentError, "a path or string is required"
315
+ def deserialize(path: nil, string: nil, data: nil)
316
+ ctx = if data
317
+ data
318
+ elsif path.nil? and string.nil?
319
+ raise ArgumentError, "a path, string, or data payload is required"
316
320
  elsif path
317
- ::File.binread(path)
321
+ LLM.json.load(::File.binread(path))
318
322
  else
319
- string
323
+ LLM.json.load(string)
320
324
  end
321
- ctx = LLM.json.load(payload)
322
325
  @messages.concat [*ctx["messages"]].map { deserialize_message(_1) }
323
326
  self
324
327
  end
@@ -185,12 +185,11 @@ module LLM::Sequel
185
185
  if data.nil? || data == ""
186
186
  ctx
187
187
  else
188
- string = case options[:format]
189
- when :string then data
190
- when :json, :jsonb then LLM.json.dump(data)
188
+ case options[:format]
189
+ when :string then ctx.restore(string: data)
190
+ when :json, :jsonb then ctx.restore(data:)
191
191
  else raise ArgumentError, "Unknown format: #{options[:format].inspect}"
192
192
  end
193
- ctx.restore(string:)
194
193
  end
195
194
  end
196
195
  end
data/lib/llm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LLM
4
- VERSION = "4.16.0"
4
+ VERSION = "4.16.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.16.0
4
+ version: 4.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antar Azri