mistral-ai 1.0.0 → 1.1.1

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: 19bfd295de85b2f506daf1623bddc5966c34a0844b823fef2b30fd9de46f0dc9
4
- data.tar.gz: b1bdd0da891f5280da914601a32ec351a4a848791d5f67c3304ab9ca96f87b1c
3
+ metadata.gz: d35454c7499ef405271de5ccb410f77dcc4bbc6be2c5727e73113630c8991f5d
4
+ data.tar.gz: 88e62dfaf6d8e6c22c23dfcec8c8677f546e204d7a0e5f53d87eeeb2349a1886
5
5
  SHA512:
6
- metadata.gz: e7ec9676abe38edca924552c4bc010cb1e04e91406f0cf1c28000dd69f76ebad53567bb48fe18977e1ead0751772d75af537fa5541bd5cf4affb8a7671a8f9fe
7
- data.tar.gz: 0ca1dd38cba7bff0cd21934a0a9626ab97ff74cac5fef2fa572f7a1e87aafc8bc5191ba3a919535e7f87b8508ab7083c80cc037b7a6adb39be43fb66f8789a5c
6
+ metadata.gz: 74aaaced1816ab4ef2270284013e9101a48a4d9d3a74b151f6075b787a16870f31b5b212113c6f2c7dadd2fa1b82a0b22d73360d4972a867a58c91cb42310dee
7
+ data.tar.gz: 26246a45258074c3a78b9cf817cf32ff9c15760ab3906485067223b7fa21446cb036d5b3d4e6a1f50bf0ffa1ecee62fe1f028213ae0f89429fe66c7be728bf6d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mistral-ai (1.0.0)
4
+ mistral-ai (1.1.1)
5
5
  event_stream_parser (~> 1.0)
6
6
  faraday (~> 2.8, >= 2.8.1)
7
7
 
@@ -22,7 +22,7 @@ GEM
22
22
  language_server-protocol (3.17.0.3)
23
23
  method_source (1.0.0)
24
24
  parallel (1.24.0)
25
- parser (3.2.2.4)
25
+ parser (3.3.0.0)
26
26
  ast (~> 2.4.1)
27
27
  racc
28
28
  pry (0.14.2)
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.0.0'
12
+ gem 'mistral-ai', '~> 1.1.1'
13
13
  ```
14
14
 
15
15
  ```ruby
@@ -61,6 +61,7 @@ Result:
61
61
  - [Without Streaming Events](#without-streaming-events)
62
62
  - [Receiving Stream Events](#receiving-stream-events)
63
63
  - [embeddings](#embeddings)
64
+ - [models](#models)
64
65
  - [Streaming and Server-Sent Events (SSE)](#streaming-and-server-sent-events-sse)
65
66
  - [Server-Sent Events (SSE) Hang](#server-sent-events-sse-hang)
66
67
  - [System Messages](#system-messages)
@@ -84,11 +85,11 @@ Result:
84
85
  ### Installing
85
86
 
86
87
  ```sh
87
- gem install mistral-ai -v 1.0.0
88
+ gem install mistral-ai -v 1.1.1
88
89
  ```
89
90
 
90
91
  ```sh
91
- gem 'mistral-ai', '~> 1.0.0'
92
+ gem 'mistral-ai', '~> 1.1.1'
92
93
  ```
93
94
 
94
95
  ### Credentials
@@ -270,6 +271,45 @@ Result:
270
271
 
271
272
  ```
272
273
 
274
+ #### models
275
+
276
+ ```ruby
277
+ result = client.models
278
+ ```
279
+
280
+ Result:
281
+ ```ruby
282
+ { 'object' => 'list',
283
+ 'data' =>
284
+ [{ 'id' => 'mistral-medium',
285
+ 'object' => 'model',
286
+ 'created' => 1_703_855_983,
287
+ 'owned_by' => 'mistralai',
288
+ 'root' => nil,
289
+ 'parent' => nil,
290
+ 'permission' =>
291
+ [{ 'id' => 'modelperm-30...',
292
+ 'object' => 'model_permission',
293
+ 'created' => 1_703_855_983,
294
+ 'allow_create_engine' => false,
295
+ 'allow_sampling' => true,
296
+ 'allow_logprobs' => false,
297
+ 'allow_search_indices' => false,
298
+ 'allow_view' => true,
299
+ 'allow_fine_tuning' => false,
300
+ 'organization' => '*',
301
+ 'group' => nil,
302
+ 'is_blocking' => false }] },
303
+ { 'id' => 'mistral-small',
304
+ 'object' => 'model',
305
+ 'created' => 1_703_855_983,
306
+ 'owned_by' => 'mistralai',
307
+ # ...
308
+ },
309
+ # ...
310
+ ] }
311
+ ```
312
+
273
313
  ### Streaming and Server-Sent Events (SSE)
274
314
 
275
315
  [Server-Sent Events (SSE)](https://en.wikipedia.org/wiki/Server-sent_events) is a technology that allows certain endpoints to offer streaming capabilities, such as creating the impression that "the model is typing along with you," rather than delivering the entire answer all at once.
@@ -370,7 +410,8 @@ Mistral may launch a new endpoint that we haven't covered in the Gem yet. If tha
370
410
  result = client.request(
371
411
  'v1/chat/completions',
372
412
  { model: 'mistral-medium',
373
- messages: [{ role: 'user', content: 'hi!' }] }
413
+ messages: [{ role: 'user', content: 'hi!' }] },
414
+ request_method: 'POST', server_sent_events: true
374
415
  )
375
416
  ```
376
417
 
@@ -454,7 +495,6 @@ MistralError
454
495
 
455
496
  MissingAPIKeyError
456
497
  BlockWithoutServerSentEventsError
457
- UnsupportedError
458
498
 
459
499
  RequestError
460
500
  ```
@@ -477,7 +517,7 @@ gem build mistral-ai.gemspec
477
517
 
478
518
  gem signin
479
519
 
480
- gem push mistral-ai-1.0.0.gem
520
+ gem push mistral-ai-1.1.1.gem
481
521
  ```
482
522
 
483
523
  ### Updating the README
data/components/errors.rb CHANGED
@@ -10,7 +10,6 @@ module Mistral
10
10
 
11
11
  class MissingAPIKeyError < MistralError; end
12
12
  class BlockWithoutServerSentEventsError < MistralError; end
13
- class UnsupportedError < MistralError; end
14
13
 
15
14
  class RequestError < MistralError
16
15
  attr_reader :request, :payload
@@ -43,13 +43,17 @@ module Mistral
43
43
  request('v1/chat/completions', payload, server_sent_events:, &callback)
44
44
  end
45
45
 
46
- def embeddings(payload, server_sent_events: nil, &callback)
46
+ def embeddings(payload, _server_sent_events: nil, &callback)
47
47
  request('v1/embeddings', payload, server_sent_events: false, &callback)
48
48
  end
49
49
 
50
- def request(path, payload, server_sent_events: nil, &callback)
50
+ def models(_server_sent_events: nil, &callback)
51
+ request('v1/models', nil, server_sent_events: false, request_method: 'GET', &callback)
52
+ end
53
+
54
+ def request(path, payload = nil, server_sent_events: nil, request_method: 'POST', &callback)
51
55
  server_sent_events_enabled = server_sent_events.nil? ? @server_sent_events : server_sent_events
52
- url = "#{@address}/#{path}"
56
+ url = "#{@address}#{path}"
53
57
 
54
58
  if !callback.nil? && !server_sent_events_enabled
55
59
  raise BlockWithoutServerSentEventsError,
@@ -58,15 +62,17 @@ module Mistral
58
62
 
59
63
  results = []
60
64
 
65
+ method_to_call = request_method.to_s.strip.downcase.to_sym
66
+
61
67
  response = Faraday.new(request: @request_options) do |faraday|
62
68
  faraday.response :raise_error
63
- end.post do |request|
69
+ end.send(method_to_call) do |request|
64
70
  request.url url
65
71
  request.headers['Content-Type'] = 'application/json'
66
72
 
67
73
  request.headers['Authorization'] = "Bearer #{@api_key}" unless @api_key.nil?
68
74
 
69
- request.body = payload.to_json
75
+ request.body = payload.to_json unless payload.nil?
70
76
 
71
77
  if server_sent_events_enabled
72
78
  parser = EventStreamParser::Parser.new
@@ -108,7 +114,7 @@ module Mistral
108
114
  end
109
115
 
110
116
  def safe_parse_json(raw)
111
- raw.start_with?('{', '[') ? JSON.parse(raw) : raw
117
+ raw.to_s.lstrip.start_with?('{', '[') ? JSON.parse(raw) : raw
112
118
  rescue JSON::ParserError
113
119
  raw
114
120
  end
data/static/gem.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Mistral
4
4
  GEM = {
5
5
  name: 'mistral-ai',
6
- version: '1.0.0',
6
+ version: '1.1.1',
7
7
  author: 'gbaptista',
8
8
  summary: 'Interact with Mistral AI.',
9
9
  description: "A Ruby gem for interacting with Mistral AI's large language models.",
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.0.0'
12
+ gem 'mistral-ai', '~> 1.1.1'
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.0.0
58
+ gem install mistral-ai -v 1.1.1
59
59
  ```
60
60
 
61
61
  ```sh
62
- gem 'mistral-ai', '~> 1.0.0'
62
+ gem 'mistral-ai', '~> 1.1.1'
63
63
  ```
64
64
 
65
65
  ### Credentials
@@ -241,6 +241,45 @@ Result:
241
241
 
242
242
  ```
243
243
 
244
+ #### models
245
+
246
+ ```ruby
247
+ result = client.models
248
+ ```
249
+
250
+ Result:
251
+ ```ruby
252
+ { 'object' => 'list',
253
+ 'data' =>
254
+ [{ 'id' => 'mistral-medium',
255
+ 'object' => 'model',
256
+ 'created' => 1_703_855_983,
257
+ 'owned_by' => 'mistralai',
258
+ 'root' => nil,
259
+ 'parent' => nil,
260
+ 'permission' =>
261
+ [{ 'id' => 'modelperm-30...',
262
+ 'object' => 'model_permission',
263
+ 'created' => 1_703_855_983,
264
+ 'allow_create_engine' => false,
265
+ 'allow_sampling' => true,
266
+ 'allow_logprobs' => false,
267
+ 'allow_search_indices' => false,
268
+ 'allow_view' => true,
269
+ 'allow_fine_tuning' => false,
270
+ 'organization' => '*',
271
+ 'group' => nil,
272
+ 'is_blocking' => false }] },
273
+ { 'id' => 'mistral-small',
274
+ 'object' => 'model',
275
+ 'created' => 1_703_855_983,
276
+ 'owned_by' => 'mistralai',
277
+ # ...
278
+ },
279
+ # ...
280
+ ] }
281
+ ```
282
+
244
283
  ### Streaming and Server-Sent Events (SSE)
245
284
 
246
285
  [Server-Sent Events (SSE)](https://en.wikipedia.org/wiki/Server-sent_events) is a technology that allows certain endpoints to offer streaming capabilities, such as creating the impression that "the model is typing along with you," rather than delivering the entire answer all at once.
@@ -341,7 +380,8 @@ Mistral may launch a new endpoint that we haven't covered in the Gem yet. If tha
341
380
  result = client.request(
342
381
  'v1/chat/completions',
343
382
  { model: 'mistral-medium',
344
- messages: [{ role: 'user', content: 'hi!' }] }
383
+ messages: [{ role: 'user', content: 'hi!' }] },
384
+ request_method: 'POST', server_sent_events: true
345
385
  )
346
386
  ```
347
387
 
@@ -425,7 +465,6 @@ MistralError
425
465
 
426
466
  MissingAPIKeyError
427
467
  BlockWithoutServerSentEventsError
428
- UnsupportedError
429
468
 
430
469
  RequestError
431
470
  ```
@@ -448,7 +487,7 @@ gem build mistral-ai.gemspec
448
487
 
449
488
  gem signin
450
489
 
451
- gem push mistral-ai-1.0.0.gem
490
+ gem push mistral-ai-1.1.1.gem
452
491
  ```
453
492
 
454
493
  ### 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.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - gbaptista
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-28 00:00:00.000000000 Z
11
+ date: 2024-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.4.22
91
+ rubygems_version: 3.3.3
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Interact with Mistral AI.