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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ruby-openai-swarm/core.rb +13 -3
- data/lib/ruby-openai-swarm/repl.rb +16 -13
- data/lib/ruby-openai-swarm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49bcf71e27c830e373b9732691667aa4ff8657dc944a8dc113fb4b13e807ccd6
|
4
|
+
data.tar.gz: 38cd26d3670e7a49652b8b52677a2a7bf722c9f5635bfef55bea296d0502c4d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f4b422f084d400ef6eea393f20a650fd02fa8b96370e4781c4228113650763c7eb84c6c1aac21daceb8251cfd83d69ec69b536dff16c3bd7be3e8b0f22a353a
|
7
|
+
data.tar.gz: f24c83ea576a7d305069eda9da308f0d39b257065897377b228c785049c41254d3889d4e82b96d40755151b801b95d3a6f8ae5550d73fb871c902c9b21755793
|
data/Gemfile.lock
CHANGED
@@ -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 |
|
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 |
|
8
|
-
|
7
|
+
response.each do |stream|
|
8
|
+
delta = stream['delta']
|
9
|
+
if delta
|
10
|
+
last_sender = delta['sender'] if delta.key?('sender')
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
21
|
-
|
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
|
32
|
+
if stream.key?("delim") && stream["delim"] == "end" && !content.empty?
|
30
33
|
puts
|
31
34
|
content = ""
|
32
35
|
end
|
33
|
-
return
|
36
|
+
return stream["response"] if stream.key?("response")
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
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.
|
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-
|
11
|
+
date: 2024-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-openai
|