mistral_rb 0.1.4 → 0.1.6
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8226b8266c5e6f6b99abb42bb7703b440221a2687870c65d67e5a9aa93c6e3d
|
4
|
+
data.tar.gz: 6ebc354b74961374e00e254e455e81cfceb06dfda60134554738017f5c2b41c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60759474220fa3ed9946731c64745938124f0e69a7b4f7e3dbe8bcfee178e3f87efbb5897687b056775af8e0e2a5fd928f67075a39e70ed9d4aeb95d4e6f1a75
|
7
|
+
data.tar.gz: eca253391a1a3c2714c00f0bd7dae098fdb580ac502b1f4d086ffdabd5b26203414598f45dcdb97a234e6791ac82671d0d7b3cc53ad5242c248bb2a8a6851c29
|
@@ -9,6 +9,7 @@ class MistralEmbeddingCreator
|
|
9
9
|
@chunker = chunker
|
10
10
|
@model = model
|
11
11
|
@api_key = api_key || ENV['MISTRAL_API_KEY']
|
12
|
+
raise 'API key not found. Please set the MISTRAL_API_KEY environment variable.' if api_key.nil? || api_key.empty?
|
12
13
|
|
13
14
|
if @api_key
|
14
15
|
@llm = MistralAPI.new(api_key: @api_key)
|
@@ -9,6 +9,7 @@ class OpenaiEmbeddingCreator
|
|
9
9
|
@chunker = chunker
|
10
10
|
@model = model
|
11
11
|
@api_key = api_key || ENV['OPENAI_API_KEY']
|
12
|
+
raise 'API key not found. Please set the OPENAI_API_KEY environment variable.' if api_key.nil? || api_key.empty?
|
12
13
|
|
13
14
|
if @api_key
|
14
15
|
@llm = OpenAI::Client.new(access_token: @api_key)
|
@@ -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
@@ -12,6 +12,7 @@ class MistralAPI
|
|
12
12
|
include HTTParty
|
13
13
|
|
14
14
|
def initialize(api_key: ENV["MISTRAL_API_KEY"], base_uri: "https://api.mistral.ai/v1")
|
15
|
+
raise 'API key not found. Please set the MISTRAL_API_KEY environment variable.' if api_key.nil? || api_key.empty?
|
15
16
|
@headers = {
|
16
17
|
"Authorization" => "Bearer #{api_key}",
|
17
18
|
"Content-Type" => "application/json"
|
@@ -41,7 +42,7 @@ class MistralAPI
|
|
41
42
|
# Handle non-streaming response
|
42
43
|
response = self.class.post("/chat/completions", body: body, headers: @headers)
|
43
44
|
parsed_response = handle_response(response)
|
44
|
-
CompletionResponse.new(parsed_response)
|
45
|
+
MistralModels::CompletionResponse.new(parsed_response)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
@@ -54,13 +55,13 @@ class MistralAPI
|
|
54
55
|
|
55
56
|
response = self.class.post("/embeddings", body: body, headers: @headers)
|
56
57
|
parsed_response = handle_response(response)
|
57
|
-
EmbeddingResponse.new(parsed_response)
|
58
|
+
MistralModels::EmbeddingResponse.new(parsed_response)
|
58
59
|
end
|
59
60
|
|
60
61
|
def list_available_models
|
61
62
|
response = self.class.get("/models", headers: @headers)
|
62
63
|
parsed_response = handle_response(response)
|
63
|
-
ModelListResponse.new(parsed_response)
|
64
|
+
MistralModels::ModelListResponse.new(parsed_response)
|
64
65
|
end
|
65
66
|
|
66
67
|
private
|
@@ -82,7 +83,7 @@ class MistralAPI
|
|
82
83
|
begin
|
83
84
|
# Only parse the JSON content if it's not the end-of-stream indicator
|
84
85
|
json_content = JSON.parse(data_content)
|
85
|
-
StreamedCompletionResponse.new(json_content)
|
86
|
+
MistralModels::StreamedCompletionResponse.new(json_content)
|
86
87
|
rescue JSON::ParserError => e
|
87
88
|
puts "Error parsing JSON: #{e.message}"
|
88
89
|
end
|
@@ -7,6 +7,8 @@ Dotenv.load()
|
|
7
7
|
class PineconeService
|
8
8
|
attr_reader :index
|
9
9
|
def initialize(pinecone_key: ENV['PINECONE_API_KEY'], pinecone_env: ENV['PINECONE_ENV'], index_name:)
|
10
|
+
raise 'API key not found. Please set the PINECONE_API_KEY environment variable.' if pinecone_key.nil? || pinecone_key.empty?
|
11
|
+
raise 'ENV not found. Please set the PINECONE_ENV environment variable.' if pinecone_env.nil? || pinecone_env.empty?
|
10
12
|
@pinecone_key = pinecone_key
|
11
13
|
@pinecone_env = pinecone_env
|
12
14
|
@index_name = index_name
|
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.6
|
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
|