cohere-ai 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +13 -11
- data/README.md +6 -4
- data/cohere-ai.gemspec +1 -1
- data/controllers/client.rb +14 -12
- data/static/gem.rb +1 -1
- data/template.md +6 -4
- metadata +4 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28430515ffef2963f9fa1ae10b23bb3563bdea2e8c8ec7fdb7c711b783249312
|
4
|
+
data.tar.gz: eb0127adde3a17d90f30bed12a4b61cd27b99b5a4a956329429020d07a3cd658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a02810e106da158ebaf4b0cbd2aef712d3fc8c29ecb9472a8346cd7e0e905c928f28d698137a0adc57956dfcb0eb7d512767a61c764e7fbee5e82e7f982ab719
|
7
|
+
data.tar.gz: e1ed417932a6c1be52d1ee733f685d3e676e0d5d6d0c0c2ccfa25ebb0cf576897124be3413650ff4185c62672a461112f285ac35c17fd3595db8c20ef9eed576
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cohere-ai (1.0.
|
5
|
-
faraday (~> 2.
|
4
|
+
cohere-ai (1.0.2)
|
5
|
+
faraday (~> 2.9)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
|
-
base64 (0.2.0)
|
12
11
|
byebug (11.1.3)
|
13
12
|
coderay (1.1.3)
|
14
|
-
|
15
|
-
|
16
|
-
faraday-net_http (>= 2.0, < 3.
|
17
|
-
|
18
|
-
|
13
|
+
dotenv (2.8.1)
|
14
|
+
faraday (2.9.0)
|
15
|
+
faraday-net_http (>= 2.0, < 3.2)
|
16
|
+
faraday-net_http (3.1.0)
|
17
|
+
net-http
|
19
18
|
json (2.7.1)
|
20
19
|
language_server-protocol (3.17.0.3)
|
21
20
|
method_source (1.0.0)
|
21
|
+
net-http (0.4.1)
|
22
|
+
uri
|
22
23
|
parallel (1.24.0)
|
23
|
-
parser (3.
|
24
|
+
parser (3.3.0.3)
|
24
25
|
ast (~> 2.4.1)
|
25
26
|
racc
|
26
27
|
pry (0.14.2)
|
@@ -31,7 +32,7 @@ GEM
|
|
31
32
|
pry (>= 0.13, < 0.15)
|
32
33
|
racc (1.7.3)
|
33
34
|
rainbow (3.1.1)
|
34
|
-
regexp_parser (2.
|
35
|
+
regexp_parser (2.9.0)
|
35
36
|
rexml (3.2.6)
|
36
37
|
rubocop (1.59.0)
|
37
38
|
json (~> 2.3)
|
@@ -47,14 +48,15 @@ GEM
|
|
47
48
|
rubocop-ast (1.30.0)
|
48
49
|
parser (>= 3.2.1.0)
|
49
50
|
ruby-progressbar (1.13.0)
|
50
|
-
ruby2_keywords (0.0.5)
|
51
51
|
unicode-display_width (2.5.0)
|
52
|
+
uri (0.13.0)
|
52
53
|
|
53
54
|
PLATFORMS
|
54
55
|
x86_64-linux
|
55
56
|
|
56
57
|
DEPENDENCIES
|
57
58
|
cohere-ai!
|
59
|
+
dotenv (~> 2.8, >= 2.8.1)
|
58
60
|
pry-byebug (~> 3.10, >= 3.10.1)
|
59
61
|
rubocop (~> 1.58)
|
60
62
|
|
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.2'
|
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.2
|
91
91
|
```
|
92
92
|
|
93
93
|
```sh
|
94
|
-
gem 'cohere-ai', '~> 1.0.
|
94
|
+
gem 'cohere-ai', '~> 1.0.2'
|
95
95
|
```
|
96
96
|
|
97
97
|
### Credentials
|
@@ -704,6 +704,8 @@ RequestError
|
|
704
704
|
```bash
|
705
705
|
bundle
|
706
706
|
rubocop -A
|
707
|
+
|
708
|
+
bundle exec ruby spec/tasks/run-client.rb
|
707
709
|
```
|
708
710
|
|
709
711
|
### Purpose
|
@@ -717,7 +719,7 @@ gem build cohere-ai.gemspec
|
|
717
719
|
|
718
720
|
gem signin
|
719
721
|
|
720
|
-
gem push cohere-ai-1.0.
|
722
|
+
gem push cohere-ai-1.0.2.gem
|
721
723
|
```
|
722
724
|
|
723
725
|
### Updating the README
|
data/cohere-ai.gemspec
CHANGED
data/controllers/client.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'faraday'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
require_relative '../
|
6
|
+
require_relative '../components/errors'
|
7
7
|
|
8
8
|
module Cohere
|
9
9
|
module Controllers
|
@@ -23,7 +23,7 @@ module Cohere
|
|
23
23
|
end
|
24
24
|
|
25
25
|
if @api_key.nil? && @address == "#{DEFAULT_ADDRESS}/"
|
26
|
-
raise MissingAPIKeyError, 'Missing API Key, which is required.'
|
26
|
+
raise Errors::MissingAPIKeyError, 'Missing API Key, which is required.'
|
27
27
|
end
|
28
28
|
|
29
29
|
@request_options = config.dig(:options, :connection, :request)
|
@@ -80,7 +80,7 @@ module Cohere
|
|
80
80
|
url = "#{@address}#{path}"
|
81
81
|
|
82
82
|
if !callback.nil? && !server_sent_events_enabled
|
83
|
-
raise BlockWithoutServerSentEventsError,
|
83
|
+
raise Errors::BlockWithoutServerSentEventsError,
|
84
84
|
'You are trying to use a block without Server Sent Events (SSE) enabled.'
|
85
85
|
end
|
86
86
|
|
@@ -109,14 +109,16 @@ module Cohere
|
|
109
109
|
|
110
110
|
partial_json += chunk
|
111
111
|
|
112
|
-
|
112
|
+
parsed_jsons = safe_parse_jsonl(partial_json)
|
113
113
|
|
114
|
-
if
|
115
|
-
|
114
|
+
if parsed_jsons
|
115
|
+
parsed_jsons.each do |parsed_json|
|
116
|
+
result = { event: parsed_json, raw: { chunk:, bytes:, env: } }
|
116
117
|
|
117
|
-
|
118
|
+
callback.call(result[:event], result[:raw]) unless callback.nil?
|
118
119
|
|
119
|
-
|
120
|
+
results << result
|
121
|
+
end
|
120
122
|
|
121
123
|
partial_json = ''
|
122
124
|
end
|
@@ -126,11 +128,11 @@ module Cohere
|
|
126
128
|
|
127
129
|
return safe_parse_json_with_fallback_to_raw(response.body) unless server_sent_events_enabled
|
128
130
|
|
129
|
-
raise IncompleteJSONReceivedError, partial_json if partial_json != ''
|
131
|
+
raise Errors::IncompleteJSONReceivedError, partial_json if partial_json != ''
|
130
132
|
|
131
133
|
results.map { |result| result[:event] }
|
132
134
|
rescue Faraday::ServerError => e
|
133
|
-
raise RequestError.new(e.message, request: e, payload:)
|
135
|
+
raise Errors::RequestError.new(e.message, request: e, payload:)
|
134
136
|
end
|
135
137
|
|
136
138
|
def safe_parse_json_with_fallback_to_raw(raw)
|
@@ -139,8 +141,8 @@ module Cohere
|
|
139
141
|
raw
|
140
142
|
end
|
141
143
|
|
142
|
-
def
|
143
|
-
raw.to_s.lstrip.start_with?('{', '[') ? JSON.parse(
|
144
|
+
def safe_parse_jsonl(raw)
|
145
|
+
raw.to_s.lstrip.start_with?('{', '[') ? raw.split("\n").map { |line| JSON.parse(line) } : raw
|
144
146
|
rescue JSON::ParserError
|
145
147
|
nil
|
146
148
|
end
|
data/static/gem.rb
CHANGED
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.2'
|
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.2
|
54
54
|
```
|
55
55
|
|
56
56
|
```sh
|
57
|
-
gem 'cohere-ai', '~> 1.0.
|
57
|
+
gem 'cohere-ai', '~> 1.0.2'
|
58
58
|
```
|
59
59
|
|
60
60
|
### Credentials
|
@@ -667,6 +667,8 @@ RequestError
|
|
667
667
|
```bash
|
668
668
|
bundle
|
669
669
|
rubocop -A
|
670
|
+
|
671
|
+
bundle exec ruby spec/tasks/run-client.rb
|
670
672
|
```
|
671
673
|
|
672
674
|
### Purpose
|
@@ -680,7 +682,7 @@ gem build cohere-ai.gemspec
|
|
680
682
|
|
681
683
|
gem signin
|
682
684
|
|
683
|
-
gem push cohere-ai-1.0.
|
685
|
+
gem push cohere-ai-1.0.2.gem
|
684
686
|
```
|
685
687
|
|
686
688
|
### Updating the README
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gbaptista
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 2.8.1
|
19
|
+
version: '2.9'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '2.
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 2.8.1
|
26
|
+
version: '2.9'
|
33
27
|
description: A Ruby gem for interacting with Cohere AI platform.
|
34
28
|
email:
|
35
29
|
executables: []
|