minds_sdk 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/minds/client.rb +2 -0
- data/lib/minds/config/base.rb +2 -0
- data/lib/minds/datasources.rb +47 -15
- data/lib/minds/minds.rb +68 -23
- data/lib/minds/rest_client.rb +8 -0
- data/lib/minds/version.rb +1 -1
- data/lib/minds.rb +5 -0
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c87aafd23aa3c79beffb7e71f2e8c5559cdeacd4d9ea313a918959d3c467f7c6
|
4
|
+
data.tar.gz: 50968756d64771da955cbbcdfe0a4f56222c01b6a1a5d4228b0916d0e2e34cf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cb27972f74e235847215349ae2ff1d43c3dd157918954d7987e3ee1d1327d4239e13180213fd7c8fcf95abedb47b3c1a059dde0e22c614b24dabd86868e8385
|
7
|
+
data.tar.gz: 5a9e256939116119fe9b2e5252dadcdc15cc5fc8083f9434bd296005e47ccff265ade9922db54a6c9554dcf895501acd15b173a9fafb84419fb41e2cd5e8d6e6
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Minds Ruby SDK
|
2
|
-
[![Gem Version](https://
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/minds_sdk)](https://rubygems.org/gems/minds_sdk)
|
3
|
+
[![Ruby](https://img.shields.io/badge/ruby->=3.0.0-ruby.svg)](https://www.ruby-lang.org/en/)
|
4
|
+
[![Documentation](https://img.shields.io/badge/docs-rubydoc.info-blue.svg)](https://www.rubydoc.info/gems/minds_sdk)
|
5
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
6
|
+
|
3
7
|
|
4
8
|
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.
|
5
9
|
|
data/lib/minds/client.rb
CHANGED
data/lib/minds/config/base.rb
CHANGED
data/lib/minds/datasources.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Minds
|
2
2
|
class DatabaseConfig
|
3
|
-
|
3
|
+
attr_accessor :name, :engine, :description, :connection_data, :tables, :created_at
|
4
4
|
|
5
5
|
def initialize(name:, engine:, description:, connection_data: {}, tables: [], created_at: nil)
|
6
6
|
@name = name
|
@@ -28,6 +28,7 @@ module Minds
|
|
28
28
|
def initialize(client:)
|
29
29
|
@client = client
|
30
30
|
end
|
31
|
+
|
31
32
|
# Create a new datasource and return it
|
32
33
|
#
|
33
34
|
# @param ds_config [DatabaseConfig] datasource configuration
|
@@ -36,23 +37,41 @@ module Minds
|
|
36
37
|
# @option ds_config [String] :description Description of the database. Used by mind to understand what data can be retrieved from it.
|
37
38
|
# @option ds_config [Hash] :connection_data (optional) Credentials to connect to the database
|
38
39
|
# @option ds_config [Array<String>] :tables (optional) List of allowed tables
|
39
|
-
# @param
|
40
|
+
# @param update [Boolean] If true, to update datasourse if exists, default is false
|
40
41
|
# @return [Datasource] The created datasource object
|
41
|
-
|
42
|
+
# @raise [ObjectNotSupported] If datasource type is not supported
|
43
|
+
#
|
44
|
+
# @example
|
45
|
+
# config = DatabaseConfig.new(
|
46
|
+
# name: 'sales_db',
|
47
|
+
# engine: 'postgres',
|
48
|
+
# connection_data: {
|
49
|
+
# host: 'localhost',
|
50
|
+
# port: 5432,
|
51
|
+
# user_name: "test"
|
52
|
+
# password: "test"
|
53
|
+
# }
|
54
|
+
# )
|
55
|
+
# datasource = datasources.create(config)
|
56
|
+
#
|
57
|
+
def create(ds_config, update = false)
|
42
58
|
name = ds_config.name
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
@client.post(path: "datasources", parameters: ds_config.to_h)
|
59
|
+
|
60
|
+
path = "datasources"
|
61
|
+
path += "/#{name}" if update
|
62
|
+
|
63
|
+
@client.send(update ? :put : :post, path: path, parameters: ds_config.to_h)
|
50
64
|
find(name)
|
51
65
|
end
|
52
66
|
|
53
|
-
#
|
67
|
+
# Return a list of datasources
|
54
68
|
#
|
55
69
|
# @return [Array<Datasource>] An array of Datasource objects
|
70
|
+
#
|
71
|
+
# @example
|
72
|
+
# datasources = datasources.all
|
73
|
+
# datasources.each { |ds| puts ds.name }
|
74
|
+
#
|
56
75
|
def all
|
57
76
|
data = @client.get(path: "datasources")
|
58
77
|
return [] if data.empty?
|
@@ -64,11 +83,16 @@ module Minds
|
|
64
83
|
end
|
65
84
|
end
|
66
85
|
|
67
|
-
#
|
86
|
+
# Find a datasource by name
|
68
87
|
#
|
69
88
|
# @param name [String] The name of the datasource to find
|
70
89
|
# @return [Datasource] The found datasource object
|
71
90
|
# @raise [ObjectNotSupported] If the datasource type is not supported
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# datasource = datasources.find('sales_db')
|
94
|
+
# puts datasource.engine
|
95
|
+
#
|
72
96
|
def find(name)
|
73
97
|
data = @client.get(path: "datasources/#{name}")
|
74
98
|
if data["engine"].nil?
|
@@ -77,10 +101,18 @@ module Minds
|
|
77
101
|
Datasource.new(**data.transform_keys(&:to_sym))
|
78
102
|
end
|
79
103
|
|
80
|
-
#
|
104
|
+
# Delete a datasource
|
105
|
+
#
|
106
|
+
# @param name [String] Datasource name to delete
|
107
|
+
# @param force [Boolean] Whether to force delete from all minds
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# # Simple delete
|
111
|
+
# datasources.destroy('old_db')
|
112
|
+
#
|
113
|
+
# # Force delete
|
114
|
+
# datasources.destroy('old_db', force: true)
|
81
115
|
#
|
82
|
-
# @param name [String] The name of the datasource to delete
|
83
|
-
# @param force: if true -remove from all minds, default: false
|
84
116
|
def destroy(name, force: false)
|
85
117
|
data = force ? { cascade: true } : nil
|
86
118
|
@client.delete(path: "datasources/#{name}", parameters: data)
|
data/lib/minds/minds.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "openai"
|
2
4
|
require "uri"
|
3
5
|
|
@@ -5,7 +7,7 @@ module Minds
|
|
5
7
|
DEFAULT_PROMPT_TEMPLATE = "Use your database tools to answer the user's question: {{question}}"
|
6
8
|
|
7
9
|
class Mind
|
8
|
-
|
10
|
+
attr_reader :name, :model_name, :provider, :parameters, :created_at, :updated_at, :datasources, :prompt_template
|
9
11
|
|
10
12
|
def initialize(client, attributes = {})
|
11
13
|
@client = client
|
@@ -20,7 +22,7 @@ module Minds
|
|
20
22
|
@datasources = attributes["datasources"]
|
21
23
|
end
|
22
24
|
|
23
|
-
# Update
|
25
|
+
# Update mind
|
24
26
|
#
|
25
27
|
# @param name [String, nil] New name of the mind (optional)
|
26
28
|
# @param model_name [String, nil] New LLM model name (optional)
|
@@ -29,20 +31,19 @@ module Minds
|
|
29
31
|
# @param datasources [Array<String, Datasource, DatabaseConfig>, nil] Alter list of datasources used by mind (optional)
|
30
32
|
# Datasource can be passed as:
|
31
33
|
# - String: name of the datasource
|
32
|
-
# - Datasource object (Minds::
|
33
|
-
# - DatabaseConfig object (Minds::
|
34
|
+
# - Datasource object (Minds::Datasource)
|
35
|
+
# - DatabaseConfig object (Minds::DatabaseConfig), in this case datasource will be created
|
34
36
|
# @param parameters [Hash, nil] Alter other parameters of the mind (optional)
|
35
37
|
# @return [void]
|
36
38
|
def update(name: nil, model_name: nil, provider: nil, prompt_template: nil, datasources: nil, parameters: nil)
|
37
39
|
data = {}
|
38
|
-
|
39
40
|
ds_names = []
|
40
41
|
datasources.each do |ds|
|
41
42
|
ds_name = @client.minds.check_datasource(ds)
|
42
43
|
ds_names << ds_name
|
43
|
-
data["datasources"] = ds_names
|
44
44
|
end if datasources
|
45
45
|
|
46
|
+
data["datasources"] = ds_names if !ds_names.empty?
|
46
47
|
data["name"] = name if name
|
47
48
|
data["model_name"] = model_name if model_name
|
48
49
|
data["provider"] = provider if provider
|
@@ -52,15 +53,26 @@ module Minds
|
|
52
53
|
@client.patch(path: "projects/#{@project}/minds/#{@name}", parameters: data)
|
53
54
|
|
54
55
|
@name = name if name && name != @name
|
56
|
+
|
57
|
+
updated_mind = @client.minds.find(@name)
|
58
|
+
|
59
|
+
@model_name = updated_mind.model_name
|
60
|
+
@datasources = updated_mind.datasources
|
61
|
+
@parameters = updated_mind.parameters
|
62
|
+
@prompt_template = updated_mind.prompt_template
|
63
|
+
@provider = updated_mind.provider
|
64
|
+
@created_at = updated_mind.created_at
|
65
|
+
@updated_at = updated_mind.updated_at
|
66
|
+
true
|
55
67
|
end
|
56
68
|
|
57
|
-
# Add
|
69
|
+
# Add datasource to mind
|
58
70
|
#
|
59
|
-
# @param datasource [String, Datasource, DatabaseConfig]
|
71
|
+
# @param datasource [String, Datasource, DatabaseConfig] Datasource to add
|
60
72
|
# Can be passed as:
|
61
73
|
# - String: name of the datasource
|
62
|
-
# - Datasource object (Minds::
|
63
|
-
# - DatabaseConfig object (Minds::
|
74
|
+
# - Datasource object (Minds::Datasource)
|
75
|
+
# - DatabaseConfig object (Minds::DatabaseConfig), in this case datasource will be created
|
64
76
|
# @return [void]
|
65
77
|
def add_datasources(datasource)
|
66
78
|
ds_name = @client.minds.check_datasource(datasource)
|
@@ -69,15 +81,18 @@ module Minds
|
|
69
81
|
|
70
82
|
mind = @client.minds.find(@name)
|
71
83
|
@datasources = mind.datasources
|
84
|
+
|
85
|
+
true
|
72
86
|
end
|
73
87
|
|
74
|
-
#
|
88
|
+
# Remove datasource from mind
|
75
89
|
#
|
76
|
-
# @param datasource [String, Datasource]
|
90
|
+
# @param datasource [String, Datasource] Datasource to remove
|
77
91
|
# Can be passed as:
|
78
92
|
# - String: name of the datasource
|
79
|
-
# - Datasource object (Minds::
|
93
|
+
# - Datasource object (Minds::Datasource)
|
80
94
|
# @return [void]
|
95
|
+
# @raise [ArgumentError] If datasource type is invalid
|
81
96
|
def destroy_datasources(datasource)
|
82
97
|
if datasource.is_a?(Datasource)
|
83
98
|
datasource = datasource.name
|
@@ -88,6 +103,7 @@ module Minds
|
|
88
103
|
|
89
104
|
mind = @client.minds.find(@name)
|
90
105
|
@datasources = mind.datasources
|
106
|
+
true
|
91
107
|
end
|
92
108
|
|
93
109
|
# Call mind completion
|
@@ -125,9 +141,14 @@ module Minds
|
|
125
141
|
@project = "mindsdb"
|
126
142
|
end
|
127
143
|
|
128
|
-
#
|
144
|
+
# Lists minds
|
145
|
+
#
|
146
|
+
# @return [Array<Mind>] List of minds
|
147
|
+
#
|
148
|
+
# @example
|
149
|
+
# minds = minds.all
|
150
|
+
# minds.each { |mind| puts mind.name }
|
129
151
|
#
|
130
|
-
# @return [Array<Mind>] An array of Mind objects
|
131
152
|
def all
|
132
153
|
data = @client.get(path: "projects/#{@project}/minds")
|
133
154
|
return [] if data.empty?
|
@@ -135,19 +156,28 @@ module Minds
|
|
135
156
|
data.map { |item| Mind.new(@client, item) }
|
136
157
|
end
|
137
158
|
|
138
|
-
#
|
159
|
+
# Find a mind by name
|
139
160
|
#
|
140
161
|
# @param name [String] The name of the mind to find
|
141
162
|
# @return [Mind] The found mind object
|
163
|
+
#
|
164
|
+
# @example
|
165
|
+
# mind = minds.find('sales_assistant')
|
166
|
+
# puts mind.model_name
|
167
|
+
#
|
142
168
|
def find(name)
|
143
169
|
data = @client.get(path: "projects/#{@project}/minds/#{name}")
|
144
170
|
Mind.new(@client, data)
|
145
171
|
end
|
146
172
|
|
147
|
-
#
|
173
|
+
# Delete a mind
|
148
174
|
#
|
149
175
|
# @param name [String] The name of the mind to delete
|
150
176
|
# @return [void]
|
177
|
+
#
|
178
|
+
# @example
|
179
|
+
# minds.destroy('old_assistant')
|
180
|
+
#
|
151
181
|
def destroy(name)
|
152
182
|
@client.delete(path: "projects/#{@project}/minds/#{name}")
|
153
183
|
end
|
@@ -165,13 +195,24 @@ module Minds
|
|
165
195
|
# - DatabaseConfig object (Minds::DatabaseConfig), in this case datasource will be created
|
166
196
|
# @param parameters [Hash, nil] Other parameters of the mind (optional)
|
167
197
|
# @param replace [Boolean] If true, remove existing mind with the same name (default: false)
|
198
|
+
# @param update [Boolean] If true, to update mind if exists(default: false)
|
168
199
|
# @return [Mind] The created mind object
|
169
|
-
|
200
|
+
#
|
201
|
+
# @example Simple creation
|
202
|
+
# mind = minds.create(name: 'sales_assistant', model_name: 'gpt-4')
|
203
|
+
#
|
204
|
+
# @example Creation with datasources
|
205
|
+
# mind = minds.create(
|
206
|
+
# name: 'sales_assistant',
|
207
|
+
# model_name: 'gpt-4',
|
208
|
+
# datasources: ['sales_db'],
|
209
|
+
# prompt_template: 'Analyze sales data: {{question}}'
|
210
|
+
# )
|
211
|
+
#
|
212
|
+
def create(name:, model_name: nil, provider: nil, prompt_template: nil, datasources: nil, parameters: nil, replace: false, update: false)
|
170
213
|
if replace
|
171
|
-
|
172
|
-
|
173
|
-
destroy(name)
|
174
|
-
end
|
214
|
+
find(name)
|
215
|
+
destroy(name)
|
175
216
|
end
|
176
217
|
|
177
218
|
ds_names = []
|
@@ -192,7 +233,9 @@ module Minds
|
|
192
233
|
datasources: ds_names
|
193
234
|
}
|
194
235
|
|
195
|
-
|
236
|
+
path = "projects/#{@project}/minds"
|
237
|
+
path += "/#{name}" if update
|
238
|
+
@client.send(update ? :put : :post, path: path, parameters: data)
|
196
239
|
find(name)
|
197
240
|
end
|
198
241
|
|
@@ -217,6 +260,8 @@ module Minds
|
|
217
260
|
return unless ds.is_a?(DatabaseConfig)
|
218
261
|
|
219
262
|
@client.datasources.find(ds.name)
|
263
|
+
rescue Faraday::ResourceNotFound
|
264
|
+
@client.datasources.create(ds)
|
220
265
|
end
|
221
266
|
end
|
222
267
|
end
|
data/lib/minds/rest_client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Minds
|
2
4
|
module RestClient
|
3
5
|
def get(path:)
|
@@ -16,6 +18,12 @@ module Minds
|
|
16
18
|
end&.body
|
17
19
|
end
|
18
20
|
|
21
|
+
def put(path:, parameters:)
|
22
|
+
conn.put(uri(path: path)) do |req|
|
23
|
+
req.body = parameters.to_json
|
24
|
+
end&.body
|
25
|
+
end
|
26
|
+
|
19
27
|
def delete(path:, parameters: nil)
|
20
28
|
conn.delete(uri(path: path)) do |req|
|
21
29
|
req.body = parameters.to_json
|
data/lib/minds/version.rb
CHANGED
data/lib/minds.rb
CHANGED
@@ -12,6 +12,11 @@ require_relative "minds/minds"
|
|
12
12
|
|
13
13
|
module Minds
|
14
14
|
class MiddlewareErrors < Faraday::Middleware
|
15
|
+
##
|
16
|
+
# Handles API error responses and provides detailed logging
|
17
|
+
#
|
18
|
+
# @param env [Hash] The Faraday environment hash
|
19
|
+
# @raise [Faraday::Error] Re-raises the original error after logging
|
15
20
|
def call(env)
|
16
21
|
@app.call(env)
|
17
22
|
rescue Faraday::Error => e
|
metadata
CHANGED
@@ -1,43 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minds_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.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-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.12'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: ruby-openai
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.3'
|
31
34
|
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
36
|
+
version: 7.3.1
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '7.3'
|
38
44
|
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: 7.3.1
|
41
47
|
description: Official Ruby SDK for Minds
|
42
48
|
email:
|
43
49
|
- tungnguyen120301@gmail.com
|