mistral-ai 1.1.1 → 1.2.0
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 +2 -1
- data/Gemfile.lock +25 -14
- data/README.md +46 -28
- data/controllers/client.rb +10 -4
- data/mistral-ai.gemspec +2 -1
- data/static/gem.rb +1 -1
- data/tasks/generate-readme.clj +1 -1
- data/template.md +21 -4
- metadata +21 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffe32ff356fd57cc72164264b4773492605133be8e3b673b8ceaf371d0cd0858
|
4
|
+
data.tar.gz: 5e986c0972820f5e1be8eb510210c9555ea94ea81986cbecd1295e33cc3a7fb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414756c816683899bf265642011f0f2598cc5fc57b1011bad67cc480f9bdd779f5ed965a76c00a1f83352699ff0e9c8b8a266fd3bc4804eccbe36ea2c396487f
|
7
|
+
data.tar.gz: 45664c86d3a7ea5cac7a10ed8d9b9c3be5f9770da27613816b7a4990ad3902aaa092e7ce02e07f01e21c789c5a09b172c34150f8c210335526b83e95b2df59a5
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mistral-ai (1.
|
4
|
+
mistral-ai (1.2.0)
|
5
5
|
event_stream_parser (~> 1.0)
|
6
|
-
faraday (~> 2.
|
6
|
+
faraday (~> 2.9)
|
7
|
+
faraday-typhoeus (~> 1.1)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
11
12
|
ast (2.4.2)
|
12
|
-
base64 (0.2.0)
|
13
13
|
byebug (11.1.3)
|
14
14
|
coderay (1.1.3)
|
15
|
+
dotenv (2.8.1)
|
16
|
+
ethon (0.16.0)
|
17
|
+
ffi (>= 1.15.0)
|
15
18
|
event_stream_parser (1.0.0)
|
16
|
-
faraday (2.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
faraday-
|
19
|
+
faraday (2.9.0)
|
20
|
+
faraday-net_http (>= 2.0, < 3.2)
|
21
|
+
faraday-net_http (3.1.0)
|
22
|
+
net-http
|
23
|
+
faraday-typhoeus (1.1.0)
|
24
|
+
faraday (~> 2.0)
|
25
|
+
typhoeus (~> 1.4)
|
26
|
+
ffi (1.16.3)
|
21
27
|
json (2.7.1)
|
22
28
|
language_server-protocol (3.17.0.3)
|
23
29
|
method_source (1.0.0)
|
30
|
+
net-http (0.4.1)
|
31
|
+
uri
|
24
32
|
parallel (1.24.0)
|
25
|
-
parser (3.3.0.
|
33
|
+
parser (3.3.0.5)
|
26
34
|
ast (~> 2.4.1)
|
27
35
|
racc
|
28
36
|
pry (0.14.2)
|
@@ -33,13 +41,13 @@ GEM
|
|
33
41
|
pry (>= 0.13, < 0.15)
|
34
42
|
racc (1.7.3)
|
35
43
|
rainbow (3.1.1)
|
36
|
-
regexp_parser (2.
|
44
|
+
regexp_parser (2.9.0)
|
37
45
|
rexml (3.2.6)
|
38
|
-
rubocop (1.
|
46
|
+
rubocop (1.60.2)
|
39
47
|
json (~> 2.3)
|
40
48
|
language_server-protocol (>= 3.17.0)
|
41
49
|
parallel (~> 1.10)
|
42
|
-
parser (>= 3.
|
50
|
+
parser (>= 3.3.0.2)
|
43
51
|
rainbow (>= 2.2.2, < 4.0)
|
44
52
|
regexp_parser (>= 1.8, < 3.0)
|
45
53
|
rexml (>= 3.2.5, < 4.0)
|
@@ -49,16 +57,19 @@ GEM
|
|
49
57
|
rubocop-ast (1.30.0)
|
50
58
|
parser (>= 3.2.1.0)
|
51
59
|
ruby-progressbar (1.13.0)
|
52
|
-
|
60
|
+
typhoeus (1.4.1)
|
61
|
+
ethon (>= 0.9.0)
|
53
62
|
unicode-display_width (2.5.0)
|
63
|
+
uri (0.13.0)
|
54
64
|
|
55
65
|
PLATFORMS
|
56
66
|
x86_64-linux
|
57
67
|
|
58
68
|
DEPENDENCIES
|
69
|
+
dotenv (~> 2.8, >= 2.8.1)
|
59
70
|
mistral-ai!
|
60
71
|
pry-byebug (~> 3.10, >= 3.10.1)
|
61
|
-
rubocop (~> 1.
|
72
|
+
rubocop (~> 1.60, >= 1.60.2)
|
62
73
|
|
63
74
|
BUNDLED WITH
|
64
75
|
2.4.22
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ A Ruby gem for interacting with [Mistral AI](https://mistral.ai)'s large languag
|
|
9
9
|
## TL;DR and Quick Start
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'mistral-ai', '~> 1.
|
12
|
+
gem 'mistral-ai', '~> 1.2.0'
|
13
13
|
```
|
14
14
|
|
15
15
|
```ruby
|
@@ -51,32 +51,33 @@ Result:
|
|
51
51
|
- [TL;DR and Quick Start](#tldr-and-quick-start)
|
52
52
|
- [Index](#index)
|
53
53
|
- [Setup](#setup)
|
54
|
-
|
55
|
-
|
54
|
+
- [Installing](#installing)
|
55
|
+
- [Credentials](#credentials)
|
56
56
|
- [Usage](#usage)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
- [
|
73
|
-
|
74
|
-
|
75
|
-
|
57
|
+
- [Client](#client)
|
58
|
+
- [Custom Address](#custom-address)
|
59
|
+
- [Methods](#methods)
|
60
|
+
- [chat_completions](#chat_completions)
|
61
|
+
- [Without Streaming Events](#without-streaming-events)
|
62
|
+
- [Receiving Stream Events](#receiving-stream-events)
|
63
|
+
- [embeddings](#embeddings)
|
64
|
+
- [models](#models)
|
65
|
+
- [Streaming and Server-Sent Events (SSE)](#streaming-and-server-sent-events-sse)
|
66
|
+
- [Server-Sent Events (SSE) Hang](#server-sent-events-sse-hang)
|
67
|
+
- [System Messages](#system-messages)
|
68
|
+
- [Back-and-Forth Conversations](#back-and-forth-conversations)
|
69
|
+
- [New Functionalities and APIs](#new-functionalities-and-apis)
|
70
|
+
- [Request Options](#request-options)
|
71
|
+
- [Adapter](#adapter)
|
72
|
+
- [Timeout](#timeout)
|
73
|
+
- [Error Handling](#error-handling)
|
74
|
+
- [Rescuing](#rescuing)
|
75
|
+
- [For Short](#for-short)
|
76
|
+
- [Errors](#errors)
|
76
77
|
- [Development](#development)
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
- [Purpose](#purpose)
|
79
|
+
- [Publish to RubyGems](#publish-to-rubygems)
|
80
|
+
- [Updating the README](#updating-the-readme)
|
80
81
|
- [Resources and References](#resources-and-references)
|
81
82
|
- [Disclaimer](#disclaimer)
|
82
83
|
|
@@ -85,11 +86,11 @@ Result:
|
|
85
86
|
### Installing
|
86
87
|
|
87
88
|
```sh
|
88
|
-
gem install mistral-ai -v 1.
|
89
|
+
gem install mistral-ai -v 1.2.0
|
89
90
|
```
|
90
91
|
|
91
92
|
```sh
|
92
|
-
gem 'mistral-ai', '~> 1.
|
93
|
+
gem 'mistral-ai', '~> 1.2.0'
|
93
94
|
```
|
94
95
|
|
95
96
|
### Credentials
|
@@ -417,6 +418,21 @@ result = client.request(
|
|
417
418
|
|
418
419
|
### Request Options
|
419
420
|
|
421
|
+
#### Adapter
|
422
|
+
|
423
|
+
The gem uses [Faraday](https://github.com/lostisland/faraday) with the [Typhoeus](https://github.com/typhoeus/typhoeus) adapter by default.
|
424
|
+
|
425
|
+
You can use a different adapter if you want:
|
426
|
+
|
427
|
+
```ruby
|
428
|
+
require 'faraday/net_http'
|
429
|
+
|
430
|
+
client = Mistral.new(
|
431
|
+
credentials: { api_key: ENV['MISTRAL_API_KEY'] },
|
432
|
+
options: { connection: { adapter: :net_http } }
|
433
|
+
)
|
434
|
+
```
|
435
|
+
|
420
436
|
#### Timeout
|
421
437
|
|
422
438
|
You can set the maximum number of seconds to wait for the request to complete with the `timeout` option:
|
@@ -504,6 +520,8 @@ RequestError
|
|
504
520
|
```bash
|
505
521
|
bundle
|
506
522
|
rubocop -A
|
523
|
+
|
524
|
+
bundle exec ruby spec/tasks/run-client.rb
|
507
525
|
```
|
508
526
|
|
509
527
|
### Purpose
|
@@ -517,7 +535,7 @@ gem build mistral-ai.gemspec
|
|
517
535
|
|
518
536
|
gem signin
|
519
537
|
|
520
|
-
gem push mistral-ai-1.
|
538
|
+
gem push mistral-ai-1.2.0.gem
|
521
539
|
```
|
522
540
|
|
523
541
|
### Updating the README
|
data/controllers/client.rb
CHANGED
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'event_stream_parser'
|
4
4
|
require 'faraday'
|
5
|
+
require 'faraday/typhoeus'
|
5
6
|
require 'json'
|
6
7
|
|
7
|
-
require_relative '../
|
8
|
+
require_relative '../components/errors'
|
8
9
|
|
9
10
|
module Mistral
|
10
11
|
module Controllers
|
@@ -13,6 +14,8 @@ module Mistral
|
|
13
14
|
|
14
15
|
ALLOWED_REQUEST_OPTIONS = %i[timeout open_timeout read_timeout write_timeout].freeze
|
15
16
|
|
17
|
+
DEFAULT_FARADAY_ADAPTER = :typhoeus
|
18
|
+
|
16
19
|
def initialize(config)
|
17
20
|
@api_key = config.dig(:credentials, :api_key)
|
18
21
|
@server_sent_events = config.dig(:options, :server_sent_events)
|
@@ -24,7 +27,7 @@ module Mistral
|
|
24
27
|
end
|
25
28
|
|
26
29
|
if @api_key.nil? && @address == "#{DEFAULT_ADDRESS}/"
|
27
|
-
raise MissingAPIKeyError, 'Missing API Key, which is required.'
|
30
|
+
raise Errors::MissingAPIKeyError, 'Missing API Key, which is required.'
|
28
31
|
end
|
29
32
|
|
30
33
|
@request_options = config.dig(:options, :connection, :request)
|
@@ -36,6 +39,8 @@ module Mistral
|
|
36
39
|
else
|
37
40
|
{}
|
38
41
|
end
|
42
|
+
|
43
|
+
@faraday_adapter = config.dig(:options, :connection, :adapter) || DEFAULT_FARADAY_ADAPTER
|
39
44
|
end
|
40
45
|
|
41
46
|
def chat_completions(payload, server_sent_events: nil, &callback)
|
@@ -56,7 +61,7 @@ module Mistral
|
|
56
61
|
url = "#{@address}#{path}"
|
57
62
|
|
58
63
|
if !callback.nil? && !server_sent_events_enabled
|
59
|
-
raise BlockWithoutServerSentEventsError,
|
64
|
+
raise Errors::BlockWithoutServerSentEventsError,
|
60
65
|
'You are trying to use a block without Server Sent Events (SSE) enabled.'
|
61
66
|
end
|
62
67
|
|
@@ -65,6 +70,7 @@ module Mistral
|
|
65
70
|
method_to_call = request_method.to_s.strip.downcase.to_sym
|
66
71
|
|
67
72
|
response = Faraday.new(request: @request_options) do |faraday|
|
73
|
+
faraday.adapter @faraday_adapter
|
68
74
|
faraday.response :raise_error
|
69
75
|
end.send(method_to_call) do |request|
|
70
76
|
request.url url
|
@@ -110,7 +116,7 @@ module Mistral
|
|
110
116
|
|
111
117
|
results.map { |result| result[:event] }
|
112
118
|
rescue Faraday::ServerError => e
|
113
|
-
raise RequestError.new(e.message, request: e, payload:)
|
119
|
+
raise Errors::RequestError.new(e.message, request: e, payload:)
|
114
120
|
end
|
115
121
|
|
116
122
|
def safe_parse_json(raw)
|
data/mistral-ai.gemspec
CHANGED
@@ -30,7 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.require_paths = ['ports/dsl']
|
31
31
|
|
32
32
|
spec.add_dependency 'event_stream_parser', '~> 1.0'
|
33
|
-
spec.add_dependency 'faraday', '~> 2.
|
33
|
+
spec.add_dependency 'faraday', '~> 2.9'
|
34
|
+
spec.add_dependency 'faraday-typhoeus', '~> 1.1'
|
34
35
|
|
35
36
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
36
37
|
end
|
data/static/gem.rb
CHANGED
data/tasks/generate-readme.clj
CHANGED
data/template.md
CHANGED
@@ -9,7 +9,7 @@ A Ruby gem for interacting with [Mistral AI](https://mistral.ai)'s large languag
|
|
9
9
|
## TL;DR and Quick Start
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'mistral-ai', '~> 1.
|
12
|
+
gem 'mistral-ai', '~> 1.2.0'
|
13
13
|
```
|
14
14
|
|
15
15
|
```ruby
|
@@ -55,11 +55,11 @@ Result:
|
|
55
55
|
### Installing
|
56
56
|
|
57
57
|
```sh
|
58
|
-
gem install mistral-ai -v 1.
|
58
|
+
gem install mistral-ai -v 1.2.0
|
59
59
|
```
|
60
60
|
|
61
61
|
```sh
|
62
|
-
gem 'mistral-ai', '~> 1.
|
62
|
+
gem 'mistral-ai', '~> 1.2.0'
|
63
63
|
```
|
64
64
|
|
65
65
|
### Credentials
|
@@ -387,6 +387,21 @@ result = client.request(
|
|
387
387
|
|
388
388
|
### Request Options
|
389
389
|
|
390
|
+
#### Adapter
|
391
|
+
|
392
|
+
The gem uses [Faraday](https://github.com/lostisland/faraday) with the [Typhoeus](https://github.com/typhoeus/typhoeus) adapter by default.
|
393
|
+
|
394
|
+
You can use a different adapter if you want:
|
395
|
+
|
396
|
+
```ruby
|
397
|
+
require 'faraday/net_http'
|
398
|
+
|
399
|
+
client = Mistral.new(
|
400
|
+
credentials: { api_key: ENV['MISTRAL_API_KEY'] },
|
401
|
+
options: { connection: { adapter: :net_http } }
|
402
|
+
)
|
403
|
+
```
|
404
|
+
|
390
405
|
#### Timeout
|
391
406
|
|
392
407
|
You can set the maximum number of seconds to wait for the request to complete with the `timeout` option:
|
@@ -474,6 +489,8 @@ RequestError
|
|
474
489
|
```bash
|
475
490
|
bundle
|
476
491
|
rubocop -A
|
492
|
+
|
493
|
+
bundle exec ruby spec/tasks/run-client.rb
|
477
494
|
```
|
478
495
|
|
479
496
|
### Purpose
|
@@ -487,7 +504,7 @@ gem build mistral-ai.gemspec
|
|
487
504
|
|
488
505
|
gem signin
|
489
506
|
|
490
|
-
gem push mistral-ai-1.
|
507
|
+
gem push mistral-ai-1.2.0.gem
|
491
508
|
```
|
492
509
|
|
493
510
|
### Updating the README
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mistral-ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.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: 2024-
|
11
|
+
date: 2024-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|
@@ -30,22 +30,30 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 2.8.1
|
33
|
+
version: '2.9'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '2.
|
44
|
-
|
40
|
+
version: '2.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday-typhoeus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
45
53
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
54
|
+
version: '1.1'
|
47
55
|
description: A Ruby gem for interacting with Mistral AI's large language models.
|
48
|
-
email:
|
56
|
+
email:
|
49
57
|
executables: []
|
50
58
|
extensions: []
|
51
59
|
extra_rdoc_files: []
|
@@ -73,7 +81,7 @@ metadata:
|
|
73
81
|
homepage_uri: https://github.com/gbaptista/mistral-ai
|
74
82
|
source_code_uri: https://github.com/gbaptista/mistral-ai
|
75
83
|
rubygems_mfa_required: 'true'
|
76
|
-
post_install_message:
|
84
|
+
post_install_message:
|
77
85
|
rdoc_options: []
|
78
86
|
require_paths:
|
79
87
|
- ports/dsl
|
@@ -89,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
97
|
version: '0'
|
90
98
|
requirements: []
|
91
99
|
rubygems_version: 3.3.3
|
92
|
-
signing_key:
|
100
|
+
signing_key:
|
93
101
|
specification_version: 4
|
94
102
|
summary: Interact with Mistral AI.
|
95
103
|
test_files: []
|