cohere-ai 1.0.0 → 1.0.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -4
- data/components/errors.rb +1 -0
- data/controllers/client.rb +24 -6
- data/static/gem.rb +2 -2
- data/template.md +5 -4
- 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: a5326901fa2fcef2d71d74de376e3ca9df19d9adb65fe6cf5e1a6d0bd195b8d6
|
4
|
+
data.tar.gz: 78e162ac160c691b0060945511059a9ea185ee44105298bbf784f3a8e86fbf5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cff2fb206e5daa899b440b27280c9b155b012364319da3536e28875a14cbebbb6c6f2a00e07409ec1edc501cd9c9a87154fbd31a28c084985bf8eccab627d28
|
7
|
+
data.tar.gz: 71453d884fd1bd3e76a9c78c5c9752dd6b695d887a1448aa12d3b0421a788f3da9306a6796beebbd0335537fa81a67ddb92dd68fd965e5e9b65d26169ff58640
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ A Ruby gem for interacting with [Cohere AI](https://cohere.com).
|
|
9
9
|
## TL;DR and Quick Start
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'cohere-ai', '~> 1.0.
|
12
|
+
gem 'cohere-ai', '~> 1.0.1'
|
13
13
|
```
|
14
14
|
|
15
15
|
```ruby
|
@@ -87,11 +87,11 @@ Result:
|
|
87
87
|
### Installing
|
88
88
|
|
89
89
|
```sh
|
90
|
-
gem install cohere-ai -v 1.0.
|
90
|
+
gem install cohere-ai -v 1.0.1
|
91
91
|
```
|
92
92
|
|
93
93
|
```sh
|
94
|
-
gem 'cohere-ai', '~> 1.0.
|
94
|
+
gem 'cohere-ai', '~> 1.0.1'
|
95
95
|
```
|
96
96
|
|
97
97
|
### Credentials
|
@@ -694,6 +694,7 @@ CohereError
|
|
694
694
|
|
695
695
|
MissingAPIKeyError
|
696
696
|
BlockWithoutServerSentEventsError
|
697
|
+
IncompleteJSONReceivedError
|
697
698
|
|
698
699
|
RequestError
|
699
700
|
```
|
@@ -716,7 +717,7 @@ gem build cohere-ai.gemspec
|
|
716
717
|
|
717
718
|
gem signin
|
718
719
|
|
719
|
-
gem push cohere-ai-1.0.
|
720
|
+
gem push cohere-ai-1.0.1.gem
|
720
721
|
```
|
721
722
|
|
722
723
|
### Updating the README
|
data/components/errors.rb
CHANGED
data/controllers/client.rb
CHANGED
@@ -88,6 +88,8 @@ module Cohere
|
|
88
88
|
|
89
89
|
method_to_call = request_method.to_s.strip.downcase.to_sym
|
90
90
|
|
91
|
+
partial_json = ''
|
92
|
+
|
91
93
|
response = Faraday.new(request: @request_options) do |faraday|
|
92
94
|
faraday.response :raise_error
|
93
95
|
end.send(method_to_call) do |request|
|
@@ -105,27 +107,43 @@ module Cohere
|
|
105
107
|
raise_error.on_complete(env.merge(body: chunk))
|
106
108
|
end
|
107
109
|
|
108
|
-
|
110
|
+
partial_json += chunk
|
111
|
+
|
112
|
+
parsed_json = safe_parse_json(partial_json)
|
113
|
+
|
114
|
+
if parsed_json
|
115
|
+
result = { event: parsed_json, raw: { chunk:, bytes:, env: } }
|
109
116
|
|
110
|
-
|
117
|
+
callback.call(result[:event], result[:raw]) unless callback.nil?
|
111
118
|
|
112
|
-
|
119
|
+
results << result
|
120
|
+
|
121
|
+
partial_json = ''
|
122
|
+
end
|
113
123
|
end
|
114
124
|
end
|
115
125
|
end
|
116
126
|
|
117
|
-
return
|
127
|
+
return safe_parse_json_with_fallback_to_raw(response.body) unless server_sent_events_enabled
|
128
|
+
|
129
|
+
raise IncompleteJSONReceivedError, partial_json if partial_json != ''
|
118
130
|
|
119
131
|
results.map { |result| result[:event] }
|
120
132
|
rescue Faraday::ServerError => e
|
121
133
|
raise RequestError.new(e.message, request: e, payload:)
|
122
134
|
end
|
123
135
|
|
124
|
-
def
|
125
|
-
raw.start_with?('{', '[') ? JSON.parse(raw) : raw
|
136
|
+
def safe_parse_json_with_fallback_to_raw(raw)
|
137
|
+
raw.to_s.lstrip.start_with?('{', '[') ? JSON.parse(raw) : raw
|
126
138
|
rescue JSON::ParserError
|
127
139
|
raw
|
128
140
|
end
|
141
|
+
|
142
|
+
def safe_parse_json(raw)
|
143
|
+
raw.to_s.lstrip.start_with?('{', '[') ? JSON.parse(raw) : nil
|
144
|
+
rescue JSON::ParserError
|
145
|
+
nil
|
146
|
+
end
|
129
147
|
end
|
130
148
|
end
|
131
149
|
end
|
data/static/gem.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
module Cohere
|
4
4
|
GEM = {
|
5
5
|
name: 'cohere-ai',
|
6
|
-
version: '1.0.
|
6
|
+
version: '1.0.1',
|
7
7
|
author: 'gbaptista',
|
8
8
|
summary: 'Interact with Cohere AI.',
|
9
|
-
description:
|
9
|
+
description: 'A Ruby gem for interacting with Cohere AI platform.',
|
10
10
|
github: 'https://github.com/gbaptista/cohere-ai',
|
11
11
|
gem_server: 'https://rubygems.org',
|
12
12
|
license: 'MIT',
|
data/template.md
CHANGED
@@ -9,7 +9,7 @@ A Ruby gem for interacting with [Cohere AI](https://cohere.com).
|
|
9
9
|
## TL;DR and Quick Start
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'cohere-ai', '~> 1.0.
|
12
|
+
gem 'cohere-ai', '~> 1.0.1'
|
13
13
|
```
|
14
14
|
|
15
15
|
```ruby
|
@@ -50,11 +50,11 @@ Result:
|
|
50
50
|
### Installing
|
51
51
|
|
52
52
|
```sh
|
53
|
-
gem install cohere-ai -v 1.0.
|
53
|
+
gem install cohere-ai -v 1.0.1
|
54
54
|
```
|
55
55
|
|
56
56
|
```sh
|
57
|
-
gem 'cohere-ai', '~> 1.0.
|
57
|
+
gem 'cohere-ai', '~> 1.0.1'
|
58
58
|
```
|
59
59
|
|
60
60
|
### Credentials
|
@@ -657,6 +657,7 @@ CohereError
|
|
657
657
|
|
658
658
|
MissingAPIKeyError
|
659
659
|
BlockWithoutServerSentEventsError
|
660
|
+
IncompleteJSONReceivedError
|
660
661
|
|
661
662
|
RequestError
|
662
663
|
```
|
@@ -679,7 +680,7 @@ gem build cohere-ai.gemspec
|
|
679
680
|
|
680
681
|
gem signin
|
681
682
|
|
682
|
-
gem push cohere-ai-1.0.
|
683
|
+
gem push cohere-ai-1.0.1.gem
|
683
684
|
```
|
684
685
|
|
685
686
|
### Updating the README
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cohere-ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gbaptista
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
77
|
+
rubygems_version: 3.3.3
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Interact with Cohere AI.
|