ruby-openai-swarm 0.3.1 → 0.4.0.1

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: 455b72e5872a2f9e11dad1509769c5e3037cef23b3a622337fa419f9c8a2ab20
4
+ data.tar.gz: 8f51f50b6ee3de651073783610d26f1394f2fbdb130aa8926b5184af921cfce0
5
5
  SHA512:
6
- metadata.gz: 5a6357efdc1963cfd240fa23aaf3211b89cea7c39e04b4101a4ff2f25e48eb6810cc281a29977fcf5cc2ef33c23ffde4667334cc34374408fff8791c656273b4
7
- data.tar.gz: b241abf134b927a950e50bdd4f2bfb06a6217a5ac5b9ea5c80d306bfcce2dd24e7c7b6f1ff85c8fd6700ac3a10080cccd13354f2f15afa6533d466d46014c7a7
6
+ metadata.gz: fc109240efa4af18db7d9d2d60cf9e22fd55c36a9b9845617aa23a3ea912610001c98e0567cd34abd8dcf5e3f1cb86b85b0d474d356023912add3e2c730ad6cf
7
+ data.tar.gz: 2d5d5740139edc78c5de1116c41e57397b3fce75f114f0459889c2f49c35846473a38fe35048977a5cecb79cb27d9af7d98c9fce48fa8926666165f6766f1dd3
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.1)
5
5
  ruby-openai (~> 7.3)
6
6
 
7
7
  GEM
@@ -15,8 +15,8 @@ GEM
15
15
  base64
16
16
  faraday-net_http (>= 2.0, < 3.1)
17
17
  ruby2_keywords (>= 0.0.4)
18
- faraday-multipart (1.0.4)
19
- multipart-post (~> 2)
18
+ faraday-multipart (1.1.0)
19
+ multipart-post (~> 2.0)
20
20
  faraday-net_http (3.0.2)
21
21
  method_source (1.1.0)
22
22
  multipart-post (2.4.1)
@@ -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'], 'agent' => active_agent&.name }) 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.1"
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.1
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