omniai-google 2.6.1 → 2.6.3

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: c901bbfae98e15ee5741f97f8a28189814495b3f2b15a40cba9ffe9e4d5e62d4
4
- data.tar.gz: 3c5d7e4544a778bc05dda49e2b8d3e6e7675307d0f0985ff55676e9fbcc6ca98
3
+ metadata.gz: 1f578af1eb17aad95c7d8d95241481ea6fa606f9dbdca2bfb098e664874cbfe1
4
+ data.tar.gz: 8ffb8c563e0e1464aeaecd38d7b764227b3a13302a130c43d5a1989f9abb6cfc
5
5
  SHA512:
6
- metadata.gz: bf21ab638a26791419a04139405064bb974120b0be0a45e77981da82d204bb494c1436a270538a31540a7cc7d4c1b351aa594d773de0851ab4d79797cd767209
7
- data.tar.gz: c267e9b001991241574a7fe5895c4e3e56336191d647627c0be202db5b84d3ae568659640edde6728ac58d71067cb5d36f1aa280dfda6ebcab36c788fd321975
6
+ metadata.gz: 8db2a30f2424c265690d6d9d7910c1de1774ddc452405c64a37a323fcaa1a9f0571128ceb03d47dda98ba5c943708b26a127f881c954d533977d2ca81c377401
7
+ data.tar.gz: 3a6245e97f79785079a3490eed18cdc32f5da909863959fbef281f40df7a5da2dff4416725dd56b173c73a7dd0c06b945a52143d37a229c539e4a4eed9ea5d3d
@@ -44,34 +44,48 @@ module OmniAI
44
44
  @data[key] = value unless key.eql?("candidates")
45
45
  end
46
46
 
47
- data["candidates"].each_with_index do |candidate, index|
48
- candidate["content"]["parts"].each do |part|
49
- block&.call(OmniAI::Chat::Delta.new(text: part["text"])) if part["text"]
50
- end
47
+ data["candidates"].each do |candidate|
48
+ process_candidate!(candidate:, &block)
49
+ end
50
+ end
51
51
 
52
- merge_candidate!(candidate:, index:, &block)
52
+ # @yield [delta]
53
+ # @yieldparam delta [OmniAI::Chat::Delta]
54
+ #
55
+ # @param candidate [Hash]
56
+ def process_candidate!(candidate:, &block)
57
+ candidate["content"]["parts"].each do |part|
58
+ block&.call(OmniAI::Chat::Delta.new(text: part["text"])) if part["text"]
53
59
  end
60
+
61
+ merge_candidate!(candidate:)
54
62
  end
55
63
 
56
64
  # @param candidate [Hash]
57
- # @param index [Integer]
58
- def merge_candidate!(candidate:, index:)
65
+ def merge_candidate!(candidate:)
66
+ index = candidate["index"]
67
+ raise candidate.inspect if index.nil?
68
+
59
69
  if @data["candidates"][index].nil?
60
70
  @data["candidates"][index] = candidate
61
71
  else
62
- merge_parts!(content: @data["candidates"][index]["content"], parts: candidate["content"]["parts"])
72
+ merge_parts!(parts: candidate["content"]["parts"], candidate: @data["candidates"][index])
63
73
  end
64
74
  end
65
75
 
66
- # @param content [Hash]
67
76
  # @param parts [Array<Hash>]
68
- def merge_parts!(content:, parts:)
69
- parts.each_with_index do |part, index|
70
- if content["parts"][index].nil?
71
- content["parts"][index] = part
72
- else
73
- content["parts"][index]["text"] += part["text"]
74
- end
77
+ # @param candidate [Hash]
78
+ def merge_parts!(parts:, candidate:)
79
+ parts.each { |part| merge_part!(part:, candidate:) }
80
+ end
81
+
82
+ # @param part [Hash]
83
+ # @param into [Hash]
84
+ def merge_part!(part:, candidate:)
85
+ if candidate["content"]["parts"][-1]&.key?("text") && part["text"]
86
+ candidate["content"]["parts"][-1]["text"] += part["text"]
87
+ else
88
+ candidate["content"]["parts"] << part
75
89
  end
76
90
  end
77
91
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Google
5
- VERSION = "2.6.1"
5
+ VERSION = "2.6.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-05-08 00:00:00.000000000 Z
10
+ date: 2025-05-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: event_stream_parser