maritaca-ai 1.0.0 → 1.1.0

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: d09d3d7f30a05367ba9488b60754235fb4ecd4ad204e699aa7b7035a75329d4b
4
- data.tar.gz: f235d41d277a28ca87c6dca8037e8bb706145cf75e46386ac40e39ba28f945cf
3
+ metadata.gz: 6303b41bc438b8e903a651e906e695cca755c34820cb75c66a9f669b2b8bedc4
4
+ data.tar.gz: cf98f0c7cdd2580885e681077fb57d15c78b68d6908176bc1cff8b737adff174
5
5
  SHA512:
6
- metadata.gz: 7b2ef8109622f102f41f2a14b1c21177c5ffa0af47417b5b0d17b61f334fe32e336ae25a5fb6cc9d08c31d60f6055cde42f9ac2503169abaa0bc6ee097bc4bca
7
- data.tar.gz: 5da080135ef573549d4948c4b242dd4bc840be4db30b0313a5608f36613cd8e1cd00a1b5db503d65f2dad7ac195a411617ad8c43bae5ebd998d582fb8f374ad1
6
+ metadata.gz: e2107ca61810c3ac4c0ef71955cfd998b71451a6dd2c0ef91a3442448a38f0594d4791687c5852bf668736c5f5a3b9f954932f601cd7629c8e871592cc8a7002
7
+ data.tar.gz: bde4023b33d3afbd36cbe183a60c14fd558135d99f323686a8130b98e601d9910af4e3d81f97a08a49ffd51d1ecbec68704d3772c86c6f2a2fdaa27f982335d1
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
2
  .devcontainer
3
+ .env
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :test, :development do
8
+ gem 'dotenv', '~> 2.8', '>= 2.8.1'
8
9
  gem 'pry-byebug', '~> 3.10', '>= 3.10.1'
9
- gem 'rubocop', '~> 1.58'
10
+ gem 'rubocop', '~> 1.60', '>= 1.60.2'
10
11
  end
data/Gemfile.lock CHANGED
@@ -1,26 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maritaca-ai (1.0.0)
5
- faraday (~> 2.8, >= 2.8.1)
4
+ maritaca-ai (1.1.0)
5
+ faraday (~> 2.9)
6
+ faraday-typhoeus (~> 1.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  ast (2.4.2)
11
- base64 (0.2.0)
12
12
  byebug (11.1.3)
13
13
  coderay (1.1.3)
14
- faraday (2.8.1)
15
- base64
16
- faraday-net_http (>= 2.0, < 3.1)
17
- ruby2_keywords (>= 0.0.4)
18
- faraday-net_http (3.0.2)
14
+ dotenv (2.8.1)
15
+ ethon (0.16.0)
16
+ ffi (>= 1.15.0)
17
+ faraday (2.9.0)
18
+ faraday-net_http (>= 2.0, < 3.2)
19
+ faraday-net_http (3.1.0)
20
+ net-http
21
+ faraday-typhoeus (1.1.0)
22
+ faraday (~> 2.0)
23
+ typhoeus (~> 1.4)
24
+ ffi (1.16.3)
19
25
  json (2.7.1)
20
26
  language_server-protocol (3.17.0.3)
21
27
  method_source (1.0.0)
28
+ net-http (0.4.1)
29
+ uri
22
30
  parallel (1.24.0)
23
- parser (3.2.2.4)
31
+ parser (3.3.0.5)
24
32
  ast (~> 2.4.1)
25
33
  racc
26
34
  pry (0.14.2)
@@ -31,13 +39,13 @@ GEM
31
39
  pry (>= 0.13, < 0.15)
32
40
  racc (1.7.3)
33
41
  rainbow (3.1.1)
34
- regexp_parser (2.8.3)
42
+ regexp_parser (2.9.0)
35
43
  rexml (3.2.6)
36
- rubocop (1.59.0)
44
+ rubocop (1.60.2)
37
45
  json (~> 2.3)
38
46
  language_server-protocol (>= 3.17.0)
39
47
  parallel (~> 1.10)
40
- parser (>= 3.2.2.4)
48
+ parser (>= 3.3.0.2)
41
49
  rainbow (>= 2.2.2, < 4.0)
42
50
  regexp_parser (>= 1.8, < 3.0)
43
51
  rexml (>= 3.2.5, < 4.0)
@@ -47,16 +55,19 @@ GEM
47
55
  rubocop-ast (1.30.0)
48
56
  parser (>= 3.2.1.0)
49
57
  ruby-progressbar (1.13.0)
50
- ruby2_keywords (0.0.5)
58
+ typhoeus (1.4.1)
59
+ ethon (>= 0.9.0)
51
60
  unicode-display_width (2.5.0)
61
+ uri (0.13.0)
52
62
 
53
63
  PLATFORMS
54
64
  x86_64-linux
55
65
 
56
66
  DEPENDENCIES
67
+ dotenv (~> 2.8, >= 2.8.1)
57
68
  maritaca-ai!
58
69
  pry-byebug (~> 3.10, >= 3.10.1)
59
- rubocop (~> 1.58)
70
+ rubocop (~> 1.60, >= 1.60.2)
60
71
 
61
72
  BUNDLED WITH
62
73
  2.4.22
data/README.md CHANGED
@@ -9,7 +9,7 @@ A Ruby gem for interacting with [MariTalk](https://chat.maritaca.ai) from [Marit
9
9
  ## TL;DR and Quick Start
10
10
 
11
11
  ```ruby
12
- gem 'maritaca-ai', '~> 1.0.0'
12
+ gem 'maritaca-ai', '~> 1.1.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -36,27 +36,28 @@ Result:
36
36
  - [TL;DR and Quick Start](#tldr-and-quick-start)
37
37
  - [Index](#index)
38
38
  - [Setup](#setup)
39
- - [Installing](#installing)
40
- - [Credentials](#credentials)
39
+ - [Installing](#installing)
40
+ - [Credentials](#credentials)
41
41
  - [Usage](#usage)
42
- - [Client](#client)
43
- - [Custom Address](#custom-address)
44
- - [Methods](#methods)
45
- - [chat_inference](#chat_inference)
46
- - [Chat](#chat)
47
- - [Back-and-Forth Conversations](#back-and-forth-conversations)
48
- - [Without Chat](#without-chat)
49
- - [New Functionalities and APIs](#new-functionalities-and-apis)
50
- - [Request Options](#request-options)
51
- - [Timeout](#timeout)
52
- - [Error Handling](#error-handling)
53
- - [Rescuing](#rescuing)
54
- - [For Short](#for-short)
55
- - [Errors](#errors)
42
+ - [Client](#client)
43
+ - [Custom Address](#custom-address)
44
+ - [Methods](#methods)
45
+ - [chat_inference](#chat_inference)
46
+ - [Chat](#chat)
47
+ - [Back-and-Forth Conversations](#back-and-forth-conversations)
48
+ - [Without Chat](#without-chat)
49
+ - [New Functionalities and APIs](#new-functionalities-and-apis)
50
+ - [Request Options](#request-options)
51
+ - [Adapter](#adapter)
52
+ - [Timeout](#timeout)
53
+ - [Error Handling](#error-handling)
54
+ - [Rescuing](#rescuing)
55
+ - [For Short](#for-short)
56
+ - [Errors](#errors)
56
57
  - [Development](#development)
57
- - [Purpose](#purpose)
58
- - [Publish to RubyGems](#publish-to-rubygems)
59
- - [Updating the README](#updating-the-readme)
58
+ - [Purpose](#purpose)
59
+ - [Publish to RubyGems](#publish-to-rubygems)
60
+ - [Updating the README](#updating-the-readme)
60
61
  - [Resources and References](#resources-and-references)
61
62
  - [Disclaimer](#disclaimer)
62
63
 
@@ -65,11 +66,11 @@ Result:
65
66
  ### Installing
66
67
 
67
68
  ```sh
68
- gem install maritaca-ai -v 1.0.0
69
+ gem install maritaca-ai -v 1.1.0
69
70
  ```
70
71
 
71
72
  ```sh
72
- gem 'maritaca-ai', '~> 1.0.0'
73
+ gem 'maritaca-ai', '~> 1.1.0'
73
74
  ```
74
75
 
75
76
  ### Credentials
@@ -116,7 +117,7 @@ client = Maritaca.new(
116
117
 
117
118
  #### chat_inference
118
119
 
119
- #### Chat
120
+ ##### Chat
120
121
 
121
122
  ```ruby
122
123
  result = client.chat_inference(
@@ -131,7 +132,7 @@ Result:
131
132
  { 'answer' => 'Oi! Como posso ajudá-lo(a) hoje?' }
132
133
  ```
133
134
 
134
- #### Back-and-Forth Conversations
135
+ ##### Back-and-Forth Conversations
135
136
 
136
137
  To maintain a back-and-forth conversation, you need to append the received responses and build a history for your requests:
137
138
 
@@ -152,7 +153,7 @@ Result:
152
153
  { 'answer' => 'Seu nome é Tamanduá.' }
153
154
  ```
154
155
 
155
- #### Without Chat
156
+ ##### Without Chat
156
157
 
157
158
  You can prompt the model without using chat mode:
158
159
 
@@ -187,6 +188,21 @@ result = client.request(
187
188
 
188
189
  ### Request Options
189
190
 
191
+ #### Adapter
192
+
193
+ The gem uses [Faraday](https://github.com/lostisland/faraday) with the [Typhoeus](https://github.com/typhoeus/typhoeus) adapter by default.
194
+
195
+ You can use a different adapter if you want:
196
+
197
+ ```ruby
198
+ require 'faraday/net_http'
199
+
200
+ client = Maritaca.new(
201
+ credentials: { api_key: ENV['MARITACA_API_KEY'] },
202
+ options: { connection: { adapter: :net_http } }
203
+ )
204
+ ```
205
+
190
206
  #### Timeout
191
207
 
192
208
  You can set the maximum number of seconds to wait for the request to complete with the `timeout` option:
@@ -275,6 +291,8 @@ RequestError
275
291
  ```bash
276
292
  bundle
277
293
  rubocop -A
294
+
295
+ bundle exec ruby spec/tasks/run-client.rb
278
296
  ```
279
297
 
280
298
  ### Purpose
@@ -288,7 +306,7 @@ gem build maritaca-ai.gemspec
288
306
 
289
307
  gem signin
290
308
 
291
- gem push maritaca-ai-1.0.0.gem
309
+ gem push maritaca-ai-1.1.0.gem
292
310
  ```
293
311
 
294
312
  ### Updating the README
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'event_stream_parser'
4
3
  require 'faraday'
4
+ require 'faraday/typhoeus'
5
5
  require 'json'
6
6
 
7
- require_relative '../ports/dsl/maritaca-ai/errors'
7
+ require_relative '../components/errors'
8
8
 
9
9
  module Maritaca
10
10
  module Controllers
@@ -13,6 +13,8 @@ module Maritaca
13
13
 
14
14
  ALLOWED_REQUEST_OPTIONS = %i[timeout open_timeout read_timeout write_timeout].freeze
15
15
 
16
+ DEFAULT_FARADAY_ADAPTER = :typhoeus
17
+
16
18
  def initialize(config)
17
19
  @api_key = config.dig(:credentials, :api_key)
18
20
  @server_sent_events = config.dig(:options, :server_sent_events)
@@ -24,7 +26,7 @@ module Maritaca
24
26
  end
25
27
 
26
28
  if @api_key.nil? && @address == "#{DEFAULT_ADDRESS}/"
27
- raise MissingAPIKeyError, 'Missing API Key, which is required.'
29
+ raise Errors::MissingAPIKeyError, 'Missing API Key, which is required.'
28
30
  end
29
31
 
30
32
  @request_options = config.dig(:options, :connection, :request)
@@ -36,6 +38,8 @@ module Maritaca
36
38
  else
37
39
  {}
38
40
  end
41
+
42
+ @faraday_adapter = config.dig(:options, :connection, :adapter) || DEFAULT_FARADAY_ADAPTER
39
43
  end
40
44
 
41
45
  def chat_inference(payload, server_sent_events: nil, &callback)
@@ -47,7 +51,7 @@ module Maritaca
47
51
  url = "#{@address}#{path}"
48
52
 
49
53
  if !callback.nil? && !server_sent_events_enabled
50
- raise BlockWithoutServerSentEventsError,
54
+ raise Errors::BlockWithoutServerSentEventsError,
51
55
  'You are trying to use a block without Server Sent Events (SSE) enabled.'
52
56
  end
53
57
 
@@ -58,6 +62,7 @@ module Maritaca
58
62
  partial_json = ''
59
63
 
60
64
  response = Faraday.new(request: @request_options) do |faraday|
65
+ faraday.adapter @faraday_adapter
61
66
  faraday.response :raise_error
62
67
  end.send(method_to_call) do |request|
63
68
  request.url url
@@ -95,7 +100,7 @@ module Maritaca
95
100
 
96
101
  results.map { |result| result[:event] }
97
102
  rescue Faraday::ServerError => e
98
- raise RequestError.new(e.message, request: e, payload:)
103
+ raise Errors::RequestError.new(e.message, request: e, payload:)
99
104
  end
100
105
 
101
106
  def safe_parse_json_with_fallback_to_raw(raw)
data/maritaca-ai.gemspec CHANGED
@@ -29,7 +29,8 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.require_paths = ['ports/dsl']
31
31
 
32
- spec.add_dependency 'faraday', '~> 2.8', '>= 2.8.1'
32
+ spec.add_dependency 'faraday', '~> 2.9'
33
+ spec.add_dependency 'faraday-typhoeus', '~> 1.1'
33
34
 
34
35
  spec.metadata['rubygems_mfa_required'] = 'true'
35
36
  end
data/static/gem.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Maritaca
4
4
  GEM = {
5
5
  name: 'maritaca-ai',
6
- version: '1.0.0',
6
+ version: '1.1.0',
7
7
  author: 'gbaptista',
8
8
  summary: 'Interact with Maritaca AI.',
9
9
  description: "A Ruby gem for interacting with Maritaca AI's large language models.",
@@ -23,7 +23,7 @@
23
23
  (remove nil?))]
24
24
  (->> processed-lines
25
25
  (map (fn [{:keys [level title link]}]
26
- (str (apply str (repeat (* 4 (- level 2)) " "))
26
+ (str (apply str (repeat (* 2 (- level 2)) " "))
27
27
  "- ["
28
28
  title
29
29
  "](#"
data/template.md CHANGED
@@ -9,7 +9,7 @@ A Ruby gem for interacting with [MariTalk](https://chat.maritaca.ai) from [Marit
9
9
  ## TL;DR and Quick Start
10
10
 
11
11
  ```ruby
12
- gem 'maritaca-ai', '~> 1.0.0'
12
+ gem 'maritaca-ai', '~> 1.1.0'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -40,11 +40,11 @@ Result:
40
40
  ### Installing
41
41
 
42
42
  ```sh
43
- gem install maritaca-ai -v 1.0.0
43
+ gem install maritaca-ai -v 1.1.0
44
44
  ```
45
45
 
46
46
  ```sh
47
- gem 'maritaca-ai', '~> 1.0.0'
47
+ gem 'maritaca-ai', '~> 1.1.0'
48
48
  ```
49
49
 
50
50
  ### Credentials
@@ -91,7 +91,7 @@ client = Maritaca.new(
91
91
 
92
92
  #### chat_inference
93
93
 
94
- #### Chat
94
+ ##### Chat
95
95
 
96
96
  ```ruby
97
97
  result = client.chat_inference(
@@ -106,7 +106,7 @@ Result:
106
106
  { 'answer' => 'Oi! Como posso ajudá-lo(a) hoje?' }
107
107
  ```
108
108
 
109
- #### Back-and-Forth Conversations
109
+ ##### Back-and-Forth Conversations
110
110
 
111
111
  To maintain a back-and-forth conversation, you need to append the received responses and build a history for your requests:
112
112
 
@@ -127,7 +127,7 @@ Result:
127
127
  { 'answer' => 'Seu nome é Tamanduá.' }
128
128
  ```
129
129
 
130
- #### Without Chat
130
+ ##### Without Chat
131
131
 
132
132
  You can prompt the model without using chat mode:
133
133
 
@@ -162,6 +162,21 @@ result = client.request(
162
162
 
163
163
  ### Request Options
164
164
 
165
+ #### Adapter
166
+
167
+ The gem uses [Faraday](https://github.com/lostisland/faraday) with the [Typhoeus](https://github.com/typhoeus/typhoeus) adapter by default.
168
+
169
+ You can use a different adapter if you want:
170
+
171
+ ```ruby
172
+ require 'faraday/net_http'
173
+
174
+ client = Maritaca.new(
175
+ credentials: { api_key: ENV['MARITACA_API_KEY'] },
176
+ options: { connection: { adapter: :net_http } }
177
+ )
178
+ ```
179
+
165
180
  #### Timeout
166
181
 
167
182
  You can set the maximum number of seconds to wait for the request to complete with the `timeout` option:
@@ -250,6 +265,8 @@ RequestError
250
265
  ```bash
251
266
  bundle
252
267
  rubocop -A
268
+
269
+ bundle exec ruby spec/tasks/run-client.rb
253
270
  ```
254
271
 
255
272
  ### Purpose
@@ -263,7 +280,7 @@ gem build maritaca-ai.gemspec
263
280
 
264
281
  gem signin
265
282
 
266
- gem push maritaca-ai-1.0.0.gem
283
+ gem push maritaca-ai-1.1.0.gem
267
284
  ```
268
285
 
269
286
  ### Updating the README
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maritaca-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gbaptista
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-30 00:00:00.000000000 Z
11
+ date: 2024-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,22 +16,30 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.8'
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.8'
30
- - - ">="
26
+ version: '2.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-typhoeus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
31
39
  - !ruby/object:Gem::Version
32
- version: 2.8.1
40
+ version: '1.1'
33
41
  description: A Ruby gem for interacting with Maritaca AI's large language models.
34
- email:
42
+ email:
35
43
  executables: []
36
44
  extensions: []
37
45
  extra_rdoc_files: []
@@ -59,7 +67,7 @@ metadata:
59
67
  homepage_uri: https://github.com/gbaptista/maritaca-ai
60
68
  source_code_uri: https://github.com/gbaptista/maritaca-ai
61
69
  rubygems_mfa_required: 'true'
62
- post_install_message:
70
+ post_install_message:
63
71
  rdoc_options: []
64
72
  require_paths:
65
73
  - ports/dsl
@@ -74,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
82
  - !ruby/object:Gem::Version
75
83
  version: '0'
76
84
  requirements: []
77
- rubygems_version: 3.5.3
78
- signing_key:
85
+ rubygems_version: 3.3.3
86
+ signing_key:
79
87
  specification_version: 4
80
88
  summary: Interact with Maritaca AI.
81
89
  test_files: []