mistral_rb 0.1.4 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a420d04befbc7d822678ac18d5d251e9a3804a4f50413efe6743c05f8781c61
4
- data.tar.gz: 572d1b152567b1ac54cd59ab0137eaef286732e288afcbfd79b025ced473b10d
3
+ metadata.gz: e8226b8266c5e6f6b99abb42bb7703b440221a2687870c65d67e5a9aa93c6e3d
4
+ data.tar.gz: 6ebc354b74961374e00e254e455e81cfceb06dfda60134554738017f5c2b41c6
5
5
  SHA512:
6
- metadata.gz: ca18ed1fb53190fe6146c26992e2e84525dcc596189396f883871c85dfb55507bb25c399cd290bcdadf72bd781740b8429533b3a6d05249f9a2ef0fff84551b8
7
- data.tar.gz: 4544e24b6fb292b3b489e5969b3334e75ef035c340d8d7118275c43ffc2ca23413feab2cc881d1310c203c567d0f9d84ceb2eadbc2035223e29963f78d99fa75
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
- 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.6"
5
5
  end
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
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: 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