monadic-chat 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/monadic_chat/internals.rb +16 -14
- data/lib/monadic_chat/open_ai.rb +19 -10
- data/lib/monadic_chat/version.rb +1 -1
- data/lib/monadic_chat.rb +2 -2
- 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: 9d44ae83c28ccafde3e3b2ea1d486730c2dbf5ff3cc7193dc4c25c97f6a46fbb
|
4
|
+
data.tar.gz: f69a30f93b4777b70d078b007c3342e212d3deb4bf2cf92d782fb6af6b825f07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31a241cff282c2e98eed745e4e32612dc018793832c38dddd79614479fd8b816a1c94be7ff16dc16b73858eb883d2da42b81109ed3d94e253a7e473526533386
|
7
|
+
data.tar.gz: eddd1596523564ac1f066b93c762d13b44515990ba1e479b74f6b51cf94e8fc840d45d45763757264a0c1dde21beac1b68c3652a2baf8a08ab6f306e64a818e9
|
data/CHANGELOG.md
CHANGED
@@ -152,29 +152,31 @@ class MonadicApp
|
|
152
152
|
research_mode = @mode == :research
|
153
153
|
|
154
154
|
escaping = +""
|
155
|
-
|
155
|
+
finished = false
|
156
156
|
|
157
157
|
res = @completion.run(params,
|
158
158
|
research_mode: research_mode,
|
159
159
|
timeout_sec: SETTINGS["timeout_sec"],
|
160
160
|
num_retrials: num_retrials) do |chunk|
|
161
|
-
if
|
162
|
-
|
163
|
-
|
164
|
-
|
161
|
+
if chunk.instance_of?(Hash) && chunk["content"] == "DONE"
|
162
|
+
finished = true
|
163
|
+
elsif chunk.instance_of?(String) && !finished
|
164
|
+
if escaping
|
165
|
+
chunk = escaping + chunk
|
166
|
+
escaping = ""
|
167
|
+
end
|
165
168
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
169
|
+
if /(?:\\\z)/ =~ chunk
|
170
|
+
escaping += chunk
|
171
|
+
next
|
172
|
+
else
|
173
|
+
chunk = chunk.gsub('\\n') { "\n" }
|
174
|
+
end
|
172
175
|
|
173
|
-
|
174
|
-
|
176
|
+
print chunk
|
177
|
+
end
|
175
178
|
end
|
176
179
|
|
177
|
-
print last_chunk
|
178
180
|
print "\n"
|
179
181
|
|
180
182
|
message = case role
|
data/lib/monadic_chat/open_ai.rb
CHANGED
@@ -16,9 +16,9 @@ RETRY_WAIT_TIME_SEC = 1
|
|
16
16
|
module OpenAI
|
17
17
|
def self.default_model(research_mode: false)
|
18
18
|
if research_mode
|
19
|
-
"gpt-
|
19
|
+
"gpt-4-turbo-preview"
|
20
20
|
else
|
21
|
-
"gpt-
|
21
|
+
"gpt-4"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,13 +27,12 @@ module OpenAI
|
|
27
27
|
"gpt-3.5-turbo-1106" => "chat/completions",
|
28
28
|
"gpt-3.5-turbo" => "chat/completions",
|
29
29
|
"gpt-3.5-turbo-16k" => "chat/completions",
|
30
|
+
"gpt-4-0125-preview" => "chat/completions",
|
31
|
+
"gpt-4-turbo-preview" => "chat/completions",
|
30
32
|
"gpt-4-1106-preview" => "chat/completions",
|
31
33
|
"gpt-4" => "chat/completions",
|
32
34
|
"gpt-4-0613" => "chat/completions",
|
33
|
-
"gpt-4-32K" => "chat/completions"
|
34
|
-
"gpt-4-32k-0613" => "chat/completions",
|
35
|
-
"gpt-3.5-turbo-0613" => "chat/completions",
|
36
|
-
"gpt-3.5-turbo-16k-0613" => "chat/completions"
|
35
|
+
"gpt-4-32K" => "chat/completions"
|
37
36
|
}[model]
|
38
37
|
if res.nil?
|
39
38
|
puts ""
|
@@ -73,12 +72,16 @@ module OpenAI
|
|
73
72
|
if query["stream"]
|
74
73
|
json = nil
|
75
74
|
buffer = ""
|
76
|
-
break_flag = false
|
75
|
+
# break_flag = false
|
76
|
+
|
77
77
|
res.body.each do |chunk|
|
78
|
-
break if
|
78
|
+
break if /\Rdata: [DONE]\R/ =~ chunk
|
79
|
+
|
80
|
+
# break if break_flag
|
79
81
|
|
80
82
|
buffer << chunk
|
81
|
-
break_flag = true if /\Rdata: [DONE]\R/ =~ buffer
|
83
|
+
# break_flag = true if /\Rdata: [DONE]\R/ =~ buffer
|
84
|
+
|
82
85
|
scanner = StringScanner.new(buffer)
|
83
86
|
pattern = /data: (\{.*?\})(?=\n|\z)/m
|
84
87
|
until scanner.eos?
|
@@ -92,6 +95,7 @@ module OpenAI
|
|
92
95
|
fragment = choice.dig("delta", "content").to_s
|
93
96
|
|
94
97
|
block&.call fragment
|
98
|
+
|
95
99
|
if !json
|
96
100
|
json = res
|
97
101
|
else
|
@@ -99,7 +103,11 @@ module OpenAI
|
|
99
103
|
json["choices"][0]["text"] << fragment
|
100
104
|
end
|
101
105
|
|
102
|
-
|
106
|
+
if choice["finish_reason"] == "length" || choice["finish_reason"] == "stop"
|
107
|
+
finish = { "type" => "message", "content" => "DONE" }
|
108
|
+
block&.call finish
|
109
|
+
break
|
110
|
+
end
|
103
111
|
rescue JSON::ParserError
|
104
112
|
res = { "type" => "error", "content" => "Error: JSON Parsing" }
|
105
113
|
pp res
|
@@ -156,6 +164,7 @@ module OpenAI
|
|
156
164
|
method = OpenAI.model_to_method(params["model"])
|
157
165
|
|
158
166
|
response = OpenAI.query(@access_token, "post", method, timeout_sec, params, &block)
|
167
|
+
|
159
168
|
if response["error"]
|
160
169
|
raise response["error"]["message"]
|
161
170
|
elsif response["choices"][0]["finish_reason"] == "length"
|
data/lib/monadic_chat/version.rb
CHANGED
data/lib/monadic_chat.rb
CHANGED
@@ -27,8 +27,8 @@ Oj.mimic_JSON
|
|
27
27
|
|
28
28
|
module MonadicChat
|
29
29
|
SETTINGS = {
|
30
|
-
"normal_model" => "gpt-
|
31
|
-
"research_model" => "gpt-
|
30
|
+
"normal_model" => "gpt-4",
|
31
|
+
"research_model" => "gpt-4-turbo-preview",
|
32
32
|
"max_tokens_wiki" => 1000,
|
33
33
|
"num_retrials" => 2,
|
34
34
|
"min_query_size" => 5,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monadic-chat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yohasebe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|