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 +4 -4
- data/README.md +16 -8
- data/lib/minds/client.rb +2 -8
- data/lib/minds/config/base.rb +2 -1
- data/lib/minds/resources/datasources.rb +2 -1
- data/lib/minds/resources/minds.rb +9 -19
- data/lib/minds/version.rb +1 -1
- 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: d88ff0f758abeb81dc3f474ec4cbdbd09ea71ab231a0b1fa6c4f69f3b55b955f
|
4
|
+
data.tar.gz: dc0e152e583e199c4a7767009003742ca8ad32acae8c8ff6090a19f83ff17609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c39da018fb204e1967817196bfd71f1e643dd7c3f29e7fff81b01aa95c7b255f95d2b49d71882ca5bc972802b574d336e6eb122742feedc20ed13674e23401f9
|
7
|
+
data.tar.gz: b1c59d6961862d5636cef58058617dc06e5cf47be66c5b6f0a3f1f8b393ed0a0c9f433fd99466864687c8333b47afe4f7585f1fad16aff7f1cd1a0a6e560a587
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# Minds Ruby SDK
|
2
|
+
[](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
|
-
|
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
|
-
|
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/
|
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.
|
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
|
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
|
|
data/lib/minds/config/base.rb
CHANGED
@@ -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
|
-
|
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: @
|
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: @
|
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
|
-
|
154
|
-
|
155
|
-
|
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
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.
|
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-
|
11
|
+
date: 2024-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|