minds_sdk 0.1.0 → 0.1.1

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: 7c7f832efbb02c672f51644db5065474eb0795f5a34da8f97b1dcd345d43cd02
4
- data.tar.gz: 6f0518f9fb72275fe165e1ef5ce47433f38eadfcf755c7dc0716d85cb488505f
3
+ metadata.gz: d88ff0f758abeb81dc3f474ec4cbdbd09ea71ab231a0b1fa6c4f69f3b55b955f
4
+ data.tar.gz: dc0e152e583e199c4a7767009003742ca8ad32acae8c8ff6090a19f83ff17609
5
5
  SHA512:
6
- metadata.gz: 1c0b304a9f92c73c61e9d96d9e9ef33e726dffd39740e92185ae6543eec606e2a3ea8b4dcdfcb3eb1e775f20ffbff445a1fb26e44e175c347d78d4432da41c93
7
- data.tar.gz: 822c1f3baa51a8f9385787c0f984f9241b68e5b13df67c1d281cdf626c6937c68c0c49bbae493948f8a6e811c140378e23e092a923a69a0bae7e322c89e963d2
6
+ metadata.gz: c39da018fb204e1967817196bfd71f1e643dd7c3f29e7fff81b01aa95c7b255f95d2b49d71882ca5bc972802b574d336e6eb122742feedc20ed13674e23401f9
7
+ data.tar.gz: b1c59d6961862d5636cef58058617dc06e5cf47be66c5b6f0a3f1f8b393ed0a0c9f433fd99466864687c8333b47afe4f7585f1fad16aff7f1cd1a0a6e560a587
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Minds Ruby SDK
2
+ [![Gem Version](https://badge.fury.io/rb/minds_sdk.svg)](https://badge.fury.io/rb/minds_sdk)
2
3
 
3
4
  Minds Ruby SDK provides an interface to interact with the Minds AI system API. It allows you to create and manage "minds" (artificial intelligences), create chat completions, and manage data sources.
4
5
 
6
+ The best starting point is the [Mind Website](https://docs.mdb.ai/docs/data-mind), with its introduction and explanation.
7
+
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
@@ -44,7 +47,7 @@ end
44
47
  Alternatively, you can configure each client instance individually:
45
48
 
46
49
  ```ruby
47
- client = Minds::Client.new("YOUR_API_KEY", "https://mdb.ai")
50
+ client = Minds::Client.new(api_key: "YOUR_API_KEY", base_url: "https://mdb.ai")
48
51
  ```
49
52
 
50
53
  ### Initialize the Client
@@ -56,13 +59,15 @@ After configuration, you can initialize the client:
56
59
  client = Minds::Client.new
57
60
 
58
61
  # Or with instance-specific configuration
59
- client = Minds::Client.new("YOUR_API_KEY", "https://mdb.ai")
62
+ client = Minds::Client.new(api_key: "YOUR_API_KEY", base_url: "https://mdb.ai")
60
63
 
61
64
  # For a self-hosted Minds Cloud instance
62
- client = Minds::Client.new("YOUR_API_KEY", "https://<custom_cloud>.mdb.ai")
65
+ client = Minds::Client.new(api_key: "YOUR_API_KEY", base_url: "https://<custom_cloud>.mdb.ai")
63
66
  ```
67
+ > Get your minds api key [here](https://mdb.ai/apiKeys)
64
68
 
65
69
  ## Resources
70
+
66
71
  ### Creating a Data Source
67
72
 
68
73
  You can connect to various databases, such as PostgreSQL, by configuring your data source. Use the DatabaseConfig to define the connection details for your data source.
@@ -83,9 +88,10 @@ postgres_config = Minds::Resources::DatabaseConfig.new(
83
88
  tables: ['<TABLE-1>', '<TABLE-2>']
84
89
  )
85
90
 
86
- See supported [Data Sources](https://docs.mdb.ai/docs/data_sources)
87
91
  ```
88
92
 
93
+ > See supported [Data Sources](https://docs.mdb.ai/docs/data_sources)
94
+
89
95
  ### Creating a Mind
90
96
 
91
97
  You can create a mind and associate it with a data source.
@@ -132,7 +138,7 @@ mind.update(
132
138
  You can list all the minds you've created:
133
139
 
134
140
  ```ruby
135
- puts client.minds.all
141
+ client.minds.all
136
142
  ```
137
143
 
138
144
  ### Get a Mind by Name
@@ -156,7 +162,7 @@ client.minds.destroy('mind_name')
156
162
  To view all data sources:
157
163
 
158
164
  ```ruby
159
- puts client.datasources.all
165
+ client.datasources.all
160
166
  ```
161
167
 
162
168
  ### Get a Data Source by Name
@@ -195,11 +201,13 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
195
201
 
196
202
  ## Contributing
197
203
 
198
- Bug reports and pull requests are welcome on GitHub at [here](https://github.com/your_github_username/minds_ruby_sdk).
204
+ Bug reports and pull requests are welcome on GitHub at [here](https://github.com/tungnt1203/minds_ruby_sdk).
199
205
 
200
206
  ## Acknowledgments
201
207
 
202
- This SDK is built for integration with Minds, AI layer for existing databases. We would like to express our gratitude to the MindsDB team for their innovative work in making AI more accessible.
208
+ This SDK is built for integration with Minds, AI layer for existing databases. See more docs [here](https://docs.mdb.ai/docs/data-mind)
209
+
210
+ We would like to express our gratitude to the MindsDB team for their innovative work in making AI more accessible.
203
211
  For more information about MindsDB, please visit their official website: [https://mindsdb.com/](https://mindsdb.com/)
204
212
  ## License
205
213
 
data/lib/minds/client.rb CHANGED
@@ -18,16 +18,10 @@ module Minds
18
18
  end
19
19
 
20
20
  attr_accessor :base_url, :api_key
21
- DEFAULT_HOST = "https://mdb.ai"
22
21
 
23
- def initialize(api_key = nil, base_url = nil)
22
+ def initialize(api_key: nil, base_url: nil)
24
23
  # if api_key & base_url not present. Fall back to global config
25
- @base_url =
26
- if base_url.nil?
27
- Minds::Client.config.send(:base_url).nil? ? DEFAULT_HOST : Minds::Client.config.send(:base_url)
28
- else
29
- base_url
30
- end
24
+ @base_url = base_url.nil? ? Minds::Client.config.send(:base_url) : base_url
31
25
  @api_key = api_key.nil? ? Minds::Client.config.send(:api_key) : api_key
32
26
  end
33
27
 
@@ -2,9 +2,10 @@ module Minds
2
2
  module Config
3
3
  class Base
4
4
  attr_accessor :base_url, :api_key
5
+ DEFAULT_BASE_URL = "https://mdb.ai"
5
6
 
6
7
  def initialize
7
- @base_url = nil
8
+ @base_url = DEFAULT_BASE_URL
8
9
  @api_key = nil
9
10
  end
10
11
  end
@@ -61,6 +61,7 @@ module Minds
61
61
  data = self.api.get("/api/datasources").body
62
62
  data.each_with_object([]) do |item, ds_list|
63
63
  next if item["engine"].nil?
64
+
64
65
  ds_list << Datasource.new(**item.transform_keys(&:to_sym))
65
66
  end
66
67
  end
@@ -71,7 +72,7 @@ module Minds
71
72
  # @return [Datasource] The found datasource object
72
73
  # @raise [ObjectNotSupported] If the datasource type is not supported
73
74
  def find(name)
74
- data =self.api.get("api/datasources/#{name}").body
75
+ data = self.api.get("api/datasources/#{name}").body
75
76
 
76
77
  if data["engine"].nil?
77
78
  raise ObjectNotSupported, "Wrong type of datasource: #{name}"
@@ -104,22 +104,11 @@ module Minds
104
104
  # @return [String, Enumerator] If stream mode is off, returns a String.
105
105
  # If stream mode is on, returns an Enumerator of ChoiceDelta objects (as defined by OpenAI)
106
106
  def completion(message:, stream: false)
107
- parsed = URI.parse(self.api.base_url)
108
- host = parsed.host
109
- if host == "mdb.ai"
110
- llm_host = "llm.mdb.ai"
111
- else
112
- llm_host = "ai.#{host}"
113
- end
114
- parsed.host = llm_host
115
- parsed.path = ""
116
- parsed.query = nil
117
- uri_base = parsed
118
- openai_client = OpenAI::Client.new(access_token: self.api_key, uri_base: uri_base)
107
+ openai_client = OpenAI::Client.new(access_token: self.api_key, uri_base: self.base_url)
119
108
  if stream
120
109
  openai_client.chat(
121
110
  parameters: {
122
- model: @model_name,
111
+ model: @name,
123
112
  messages: [ { role: "user", content: message } ], # Required.
124
113
  temperature: 0,
125
114
  stream: proc do |chunk, _bytesize|
@@ -130,7 +119,7 @@ module Minds
130
119
  else
131
120
  response = openai_client.chat(
132
121
  parameters: {
133
- model: @model_name,
122
+ model: @name,
134
123
  messages: [ { role: "user", content: message } ],
135
124
  temperature: 0
136
125
  }
@@ -150,9 +139,10 @@ module Minds
150
139
  #
151
140
  # @return [Array<Mind>] An array of Mind objects
152
141
  def all
153
- resp = self.api.get("/api/projects/#{@project}/minds")
154
- resp.body
155
- resp.body.map { |item| Mind.new(self, item) }
142
+ data = self.api.get("/api/projects/#{@project}/minds").body
143
+ return [] if data.empty?
144
+
145
+ data.map { |item| Mind.new(self, item) }
156
146
  end
157
147
 
158
148
  # Get a mind by name
@@ -213,9 +203,8 @@ module Minds
213
203
  parameters: parameters,
214
204
  datasources: ds_names
215
205
  }.to_json
216
-
217
- find(name)
218
206
  end
207
+ find(name)
219
208
  end
220
209
 
221
210
  def check_datasource(ds)
@@ -237,6 +226,7 @@ module Minds
237
226
 
238
227
  def create_datasource_if_needed(ds)
239
228
  return unless ds.is_a?(DatabaseConfig)
229
+
240
230
  datasources = Datasources.new(self)
241
231
  datasources.find(ds.name)
242
232
  rescue Faraday::ResourceNotFound
data/lib/minds/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minds
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minds_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tungnt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-13 00:00:00.000000000 Z
11
+ date: 2024-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday