mistral_rb 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mistral_rb/response_models.rb +77 -75
- data/lib/mistral_rb/version.rb +1 -1
- data/lib/mistral_rb.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c775af119701a9e79b9aed5e79049ffcb5d3b434d8730d51e857443d1cdeb84
|
4
|
+
data.tar.gz: 43141631a0f888a09e85259832a2d30a8c3c02c8659327ff97bc859317795340
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f8513858962d88312898f29be0d2fb786d0c0e693877e404aca529c5589d0e077b267066f297b5b2b238f77507c1a3eb93e5703d63513f31bccbff386000441
|
7
|
+
data.tar.gz: 155f73296b4de0a124531c3e2c26babba0636b61ae6a39c328b815dd44b47f7124cf64ae46dc1dedfa6fc58feb099925224af1df33bb590a8587913e32d2528f
|
@@ -1,104 +1,106 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
15
|
+
class Choice
|
16
|
+
attr_reader :index, :message
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
24
|
+
class Message
|
25
|
+
attr_reader :role, :content
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
33
|
+
class EmbeddingResponse
|
34
|
+
attr_reader :id, :object, :data, :model, :usage
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
45
|
+
class Embedding
|
46
|
+
attr_reader :object, :embedding, :index
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
55
|
+
class ModelListResponse
|
56
|
+
attr_reader :object, :data
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
64
|
+
class Model
|
65
|
+
attr_reader :id, :object, :created, :owned_by, :permissions
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
76
|
+
class StreamedCompletionResponse
|
77
|
+
attr_reader :id, :object, :created, :model, :choices
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
88
|
+
class StreamedChoice
|
89
|
+
attr_reader :index, :delta, :finish_reason
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
98
|
+
class Delta
|
99
|
+
attr_reader :role, :content
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
def initialize(delta_hash)
|
102
|
+
@role = delta_hash["role"]
|
103
|
+
@content = delta_hash["content"]
|
104
|
+
end
|
103
105
|
end
|
104
106
|
end
|
data/lib/mistral_rb/version.rb
CHANGED
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
|
+
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:
|
11
|
+
date: 2024-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|