mistral_rb 0.1.4 → 0.1.5

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: 9a420d04befbc7d822678ac18d5d251e9a3804a4f50413efe6743c05f8781c61
4
- data.tar.gz: 572d1b152567b1ac54cd59ab0137eaef286732e288afcbfd79b025ced473b10d
3
+ metadata.gz: 1c775af119701a9e79b9aed5e79049ffcb5d3b434d8730d51e857443d1cdeb84
4
+ data.tar.gz: 43141631a0f888a09e85259832a2d30a8c3c02c8659327ff97bc859317795340
5
5
  SHA512:
6
- metadata.gz: ca18ed1fb53190fe6146c26992e2e84525dcc596189396f883871c85dfb55507bb25c399cd290bcdadf72bd781740b8429533b3a6d05249f9a2ef0fff84551b8
7
- data.tar.gz: 4544e24b6fb292b3b489e5969b3334e75ef035c340d8d7118275c43ffc2ca23413feab2cc881d1310c203c567d0f9d84ceb2eadbc2035223e29963f78d99fa75
6
+ metadata.gz: 2f8513858962d88312898f29be0d2fb786d0c0e693877e404aca529c5589d0e077b267066f297b5b2b238f77507c1a3eb93e5703d63513f31bccbff386000441
7
+ data.tar.gz: 155f73296b4de0a124531c3e2c26babba0636b61ae6a39c328b815dd44b47f7124cf64ae46dc1dedfa6fc58feb099925224af1df33bb590a8587913e32d2528f
@@ -1,104 +1,106 @@
1
- class CompletionResponse
2
- attr_reader :id, :object, :created, :model, :choices, :usage
3
-
4
- def initialize(response_hash)
5
- @id = response_hash["id"]
6
- @object = response_hash["object"]
7
- @created = response_hash["created"]
8
- @model = response_hash["model"]
9
- @choices = response_hash["choices"].map { |choice| Choice.new(choice) }
10
- @usage = response_hash["usage"]
1
+ module MistralModels
2
+ class CompletionResponse
3
+ attr_reader :id, :object, :created, :model, :choices, :usage
4
+
5
+ def initialize(response_hash)
6
+ @id = response_hash["id"]
7
+ @object = response_hash["object"]
8
+ @created = response_hash["created"]
9
+ @model = response_hash["model"]
10
+ @choices = response_hash["choices"].map { |choice| Choice.new(choice) }
11
+ @usage = response_hash["usage"]
12
+ end
11
13
  end
12
- end
13
14
 
14
- class Choice
15
- attr_reader :index, :message
15
+ class Choice
16
+ attr_reader :index, :message
16
17
 
17
- def initialize(choice_hash)
18
- @index = choice_hash["index"]
19
- @message = Message.new(choice_hash["message"])
18
+ def initialize(choice_hash)
19
+ @index = choice_hash["index"]
20
+ @message = Message.new(choice_hash["message"])
21
+ end
20
22
  end
21
- end
22
23
 
23
- class Message
24
- attr_reader :role, :content
24
+ class Message
25
+ attr_reader :role, :content
25
26
 
26
- def initialize(message_hash)
27
- @role = message_hash["role"]
28
- @content = message_hash["content"]
27
+ def initialize(message_hash)
28
+ @role = message_hash["role"]
29
+ @content = message_hash["content"]
30
+ end
29
31
  end
30
- end
31
32
 
32
- class EmbeddingResponse
33
- attr_reader :id, :object, :data, :model, :usage
33
+ class EmbeddingResponse
34
+ attr_reader :id, :object, :data, :model, :usage
34
35
 
35
- def initialize(response_hash)
36
- @id = response_hash["id"]
37
- @object = response_hash["object"]
38
- @data = response_hash["data"].map { |embedding_data| Embedding.new(embedding_data) }
39
- @model = response_hash["model"]
40
- @usage = response_hash["usage"]
36
+ def initialize(response_hash)
37
+ @id = response_hash["id"]
38
+ @object = response_hash["object"]
39
+ @data = response_hash["data"].map { |embedding_data| Embedding.new(embedding_data) }
40
+ @model = response_hash["model"]
41
+ @usage = response_hash["usage"]
42
+ end
41
43
  end
42
- end
43
44
 
44
- class Embedding
45
- attr_reader :object, :embedding, :index
45
+ class Embedding
46
+ attr_reader :object, :embedding, :index
46
47
 
47
- def initialize(embedding_hash)
48
- @object = embedding_hash["object"]
49
- @embedding = embedding_hash["embedding"]
50
- @index = embedding_hash["index"]
48
+ def initialize(embedding_hash)
49
+ @object = embedding_hash["object"]
50
+ @embedding = embedding_hash["embedding"]
51
+ @index = embedding_hash["index"]
52
+ end
51
53
  end
52
- end
53
54
 
54
- class ModelListResponse
55
- attr_reader :object, :data
55
+ class ModelListResponse
56
+ attr_reader :object, :data
56
57
 
57
- def initialize(response_hash)
58
- @object = response_hash["object"]
59
- @data = response_hash["data"].map { |model_data| Model.new(model_data) }
58
+ def initialize(response_hash)
59
+ @object = response_hash["object"]
60
+ @data = response_hash["data"].map { |model_data| Model.new(model_data) }
61
+ end
60
62
  end
61
- end
62
63
 
63
- class Model
64
- attr_reader :id, :object, :created, :owned_by, :permissions
64
+ class Model
65
+ attr_reader :id, :object, :created, :owned_by, :permissions
65
66
 
66
- def initialize(model_hash)
67
- @id = model_hash["id"]
68
- @object = model_hash["object"]
69
- @created = model_hash["created"]
70
- @owned_by = model_hash["owned_by"]
71
- @permissions = model_hash["permission"] # This could be further parsed into Permission objects if detailed parsing is required
67
+ def initialize(model_hash)
68
+ @id = model_hash["id"]
69
+ @object = model_hash["object"]
70
+ @created = model_hash["created"]
71
+ @owned_by = model_hash["owned_by"]
72
+ @permissions = model_hash["permission"] # This could be further parsed into Permission objects if detailed parsing is required
73
+ end
72
74
  end
73
- end
74
75
 
75
- class StreamedCompletionResponse
76
- attr_reader :id, :object, :created, :model, :choices
76
+ class StreamedCompletionResponse
77
+ attr_reader :id, :object, :created, :model, :choices
77
78
 
78
- def initialize(response_hash)
79
- @id = response_hash["id"]
80
- @object = response_hash["object"]
81
- @created = response_hash["created"]
82
- @model = response_hash["model"]
83
- @choices = response_hash["choices"].map { |choice| StreamedChoice.new(choice) }
79
+ def initialize(response_hash)
80
+ @id = response_hash["id"]
81
+ @object = response_hash["object"]
82
+ @created = response_hash["created"]
83
+ @model = response_hash["model"]
84
+ @choices = response_hash["choices"].map { |choice| StreamedChoice.new(choice) }
85
+ end
84
86
  end
85
- end
86
87
 
87
- class StreamedChoice
88
- attr_reader :index, :delta, :finish_reason
88
+ class StreamedChoice
89
+ attr_reader :index, :delta, :finish_reason
89
90
 
90
- def initialize(choice_hash)
91
- @index = choice_hash["index"]
92
- @delta = Delta.new(choice_hash["delta"]) if choice_hash["delta"]
93
- @finish_reason = choice_hash["finish_reason"]
91
+ def initialize(choice_hash)
92
+ @index = choice_hash["index"]
93
+ @delta = Delta.new(choice_hash["delta"]) if choice_hash["delta"]
94
+ @finish_reason = choice_hash["finish_reason"]
95
+ end
94
96
  end
95
- end
96
97
 
97
- class Delta
98
- attr_reader :role, :content
98
+ class Delta
99
+ attr_reader :role, :content
99
100
 
100
- def initialize(delta_hash)
101
- @role = delta_hash["role"]
102
- @content = delta_hash["content"]
101
+ def initialize(delta_hash)
102
+ @role = delta_hash["role"]
103
+ @content = delta_hash["content"]
104
+ end
103
105
  end
104
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MistralRb
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/mistral_rb.rb CHANGED
@@ -41,7 +41,7 @@ class MistralAPI
41
41
  # Handle non-streaming response
42
42
  response = self.class.post("/chat/completions", body: body, headers: @headers)
43
43
  parsed_response = handle_response(response)
44
- CompletionResponse.new(parsed_response)
44
+ MistralModels::CompletionResponse.new(parsed_response)
45
45
  end
46
46
  end
47
47
 
@@ -54,13 +54,13 @@ class MistralAPI
54
54
 
55
55
  response = self.class.post("/embeddings", body: body, headers: @headers)
56
56
  parsed_response = handle_response(response)
57
- EmbeddingResponse.new(parsed_response)
57
+ MistralModels::EmbeddingResponse.new(parsed_response)
58
58
  end
59
59
 
60
60
  def list_available_models
61
61
  response = self.class.get("/models", headers: @headers)
62
62
  parsed_response = handle_response(response)
63
- ModelListResponse.new(parsed_response)
63
+ MistralModels::ModelListResponse.new(parsed_response)
64
64
  end
65
65
 
66
66
  private
@@ -82,7 +82,7 @@ class MistralAPI
82
82
  begin
83
83
  # Only parse the JSON content if it's not the end-of-stream indicator
84
84
  json_content = JSON.parse(data_content)
85
- StreamedCompletionResponse.new(json_content)
85
+ MistralModels::StreamedCompletionResponse.new(json_content)
86
86
  rescue JSON::ParserError => e
87
87
  puts "Error parsing JSON: #{e.message}"
88
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mistral_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck Stephane Ndzomga
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-26 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler