ruby-openai-swarm 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 984c58d324ae34f1a8eec694c3bca07aaf44420ce9ce322ceffbbc8c722e0ddd
4
- data.tar.gz: 4ca2dd01658cbf5091aee65e41951fc64d5f16a72ea93c9dafe4a3802d38cad2
3
+ metadata.gz: 49bcf71e27c830e373b9732691667aa4ff8657dc944a8dc113fb4b13e807ccd6
4
+ data.tar.gz: 38cd26d3670e7a49652b8b52677a2a7bf722c9f5635bfef55bea296d0502c4d1
5
5
  SHA512:
6
- metadata.gz: 5a6357efdc1963cfd240fa23aaf3211b89cea7c39e04b4101a4ff2f25e48eb6810cc281a29977fcf5cc2ef33c23ffde4667334cc34374408fff8791c656273b4
7
- data.tar.gz: b241abf134b927a950e50bdd4f2bfb06a6217a5ac5b9ea5c80d306bfcce2dd24e7c7b6f1ff85c8fd6700ac3a10080cccd13354f2f15afa6533d466d46014c7a7
6
+ metadata.gz: 0f4b422f084d400ef6eea393f20a650fd02fa8b96370e4781c4228113650763c7eb84c6c1aac21daceb8251cfd83d69ec69b536dff16c3bd7be3e8b0f22a353a
7
+ data.tar.gz: f24c83ea576a7d305069eda9da308f0d39b257065897377b228c785049c41254d3889d4e82b96d40755151b801b95d3a6f8ae5550d73fb871c902c9b21755793
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai-swarm (0.3.1)
4
+ ruby-openai-swarm (0.4.0)
5
5
  ruby-openai (~> 7.3)
6
6
 
7
7
  GEM
@@ -51,9 +51,11 @@ module OpenAISwarm
51
51
 
52
52
  if stream
53
53
  return Enumerator.new do |yielder|
54
+ yielder << { 'parameters' => create_params }
55
+
54
56
  @client.chat(parameters: create_params.merge(
55
57
  stream: proc do |chunk, _bytesize|
56
- yielder << chunk
58
+ yielder << { chunk: chunk }
57
59
  end
58
60
  ))
59
61
  end
@@ -238,7 +240,15 @@ module OpenAISwarm
238
240
  )
239
241
 
240
242
  yield({ delim: "start" }) if block_given?
241
- completion.each do |chunk|
243
+ completion.each do |stream|
244
+
245
+ # TODO(Grayson): will refactor it
246
+ if stream['parameters']
247
+ yield({ 'parameters' => stream['parameters'] }) if block_given?
248
+ end
249
+ next if stream.key?('parameters')
250
+
251
+ chunk = stream[:chunk]
242
252
  if chunk['error']
243
253
  details = {
244
254
  'response' =>
@@ -255,7 +265,7 @@ module OpenAISwarm
255
265
  delta['sender'] = active_agent.name
256
266
  end
257
267
 
258
- yield delta if block_given?
268
+ yield({ 'delta' => delta }) if block_given?
259
269
 
260
270
  delta.delete('role')
261
271
  delta.delete('sender')
@@ -4,21 +4,24 @@ module OpenAISwarm
4
4
  def process_and_print_streaming_response(response)
5
5
  content = []
6
6
  last_sender = ""
7
- response.each do |chunk|
8
- last_sender = chunk['sender'] if chunk.key?('sender')
7
+ response.each do |stream|
8
+ delta = stream['delta']
9
+ if delta
10
+ last_sender = delta['sender'] if delta.key?('sender')
9
11
 
10
- if chunk.key?("content") && !chunk["content"].nil?
11
- if content.empty? && !last_sender.empty?
12
- puts
13
- print "\033[94m#{last_sender}:\033[0m "
14
- last_sender = ""
12
+ if delta.key?("content") && !delta["content"].nil?
13
+ if content.empty? && !last_sender.empty?
14
+ puts
15
+ print "\033[94m#{last_sender}:\033[0m "
16
+ last_sender = ""
17
+ end
18
+ print delta["content"]
19
+ content << delta["content"]
15
20
  end
16
- print chunk["content"]
17
- content << chunk["content"]
18
21
  end
19
22
 
20
- if chunk.key?("tool_calls") && !chunk["tool_calls"].nil?
21
- chunk["tool_calls"].each do |tool_call|
23
+ if stream.key?("tool_calls") && !stream["tool_calls"].nil?
24
+ stream["tool_calls"].each do |tool_call|
22
25
  f = tool_call["function"]
23
26
  name = f["name"]
24
27
  next if name.nil?
@@ -26,11 +29,11 @@ module OpenAISwarm
26
29
  end
27
30
  end
28
31
 
29
- if chunk.key?("delim") && chunk["delim"] == "end" && !content.empty?
32
+ if stream.key?("delim") && stream["delim"] == "end" && !content.empty?
30
33
  puts
31
34
  content = ""
32
35
  end
33
- return chunk["response"] if chunk.key?("response")
36
+ return stream["response"] if stream.key?("response")
34
37
  end
35
38
  end
36
39
 
@@ -1,3 +1,3 @@
1
1
  module OpenAISwarm
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-openai-swarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-18 00:00:00.000000000 Z
11
+ date: 2024-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai