1
+ # frozen_string_literal: true
2
+
1
3
require "openai"
2
4
require "uri"
3
5
@@ -20,7 +22,8 @@ def initialize(client, attributes = {})
20
22
@datasources = attributes [ "datasources" ]
21
23
end
22
24
23
- # Update the mind with new parameters
25
+ ##
26
+ # Update mind
24
27
#
25
28
# @param name [String, nil] New name of the mind (optional)
26
29
# @param model_name [String, nil] New LLM model name (optional)
@@ -29,8 +32,8 @@ def initialize(client, attributes = {})
29
32
# @param datasources [Array<String, Datasource, DatabaseConfig>, nil] Alter list of datasources used by mind (optional)
30
33
# Datasource can be passed as:
31
34
# - String: name of the datasource
32
- # - Datasource object (Minds::Resources:: Datasource)
33
- # - DatabaseConfig object (Minds::Resources:: DatabaseConfig), in this case datasource will be created
35
+ # - Datasource object (Minds::Datasource)
36
+ # - DatabaseConfig object (Minds::DatabaseConfig), in this case datasource will be created
34
37
# @param parameters [Hash, nil] Alter other parameters of the mind (optional)
35
38
# @return [void]
36
39
def update ( name : nil , model_name : nil , provider : nil , prompt_template : nil , datasources : nil , parameters : nil )
@@ -54,13 +57,14 @@ def update(name: nil, model_name: nil, provider: nil, prompt_template: nil, data
54
57
@name = name if name && name != @name
55
58
end
56
59
57
- # Add a datasource to the mind
60
+ ##
61
+ # Add datasource to mind
58
62
#
59
- # @param datasource [String, Datasource, DatabaseConfig] The datasource to add
63
+ # @param datasource [String, Datasource, DatabaseConfig] Datasource to add
60
64
# Can be passed as:
61
65
# - String: name of the datasource
62
- # - Datasource object (Minds::Resources:: Datasource)
63
- # - DatabaseConfig object (Minds::Resources:: DatabaseConfig), in this case datasource will be created
66
+ # - Datasource object (Minds::Datasource)
67
+ # - DatabaseConfig object (Minds::DatabaseConfig), in this case datasource will be created
64
68
# @return [void]
65
69
def add_datasources ( datasource )
66
70
ds_name = @client . minds . check_datasource ( datasource )
@@ -71,13 +75,15 @@ def add_datasources(datasource)
71
75
@datasources = mind . datasources
72
76
end
73
77
74
- # Delete a datasource from the mind
78
+ ##
79
+ # Remove datasource from mind
75
80
#
76
- # @param datasource [String, Datasource] The datasource to delete
81
+ # @param datasource [String, Datasource] Datasource to remove
77
82
# Can be passed as:
78
83
# - String: name of the datasource
79
84
# - Datasource object (Minds::Resources::Datasource)
80
85
# @return [void]
86
+ # @raise [ArgumentError] If datasource type is invalid
81
87
def destroy_datasources ( datasource )
82
88
if datasource . is_a? ( Datasource )
83
89
datasource = datasource . name
@@ -90,6 +96,7 @@ def destroy_datasources(datasource)
90
96
@datasources = mind . datasources
91
97
end
92
98
99
+ ##
93
100
# Call mind completion
94
101
#
95
102
# @param message [String] The input question or prompt
@@ -125,34 +132,52 @@ def initialize(client:)
125
132
@project = "mindsdb"
126
133
end
127
134
128
- # Returns a list of all minds
135
+ ##
136
+ # Lists minds
137
+ #
138
+ # @return [Array<Mind>] List of minds
139
+ #
140
+ # @example
141
+ # minds = minds.all
142
+ # minds.each { |mind| puts mind.name }
129
143
#
130
- # @return [Array<Mind>] An array of Mind objects
131
144
def all
132
145
data = @client . get ( path : "projects/#{ @project } /minds" )
133
146
return [ ] if data . empty?
134
147
135
148
data . map { |item | Mind . new ( @client , item ) }
136
149
end
137
150
138
- # Get a mind by name
151
+ ##
152
+ # Find a mind by name
139
153
#
140
154
# @param name [String] The name of the mind to find
141
155
# @return [Mind] The found mind object
156
+ #
157
+ # @example
158
+ # mind = minds.find('sales_assistant')
159
+ # puts mind.model_name
160
+ #
142
161
def find ( name )
143
162
data = @client . get ( path : "projects/#{ @project } /minds/#{ name } " )
144
163
Mind . new ( @client , data )
145
164
end
146
165
147
- # Drop (delete) a mind by name
166
+ ##
167
+ # Deletes a mind
148
168
#
149
169
# @param name [String] The name of the mind to delete
150
170
# @return [void]
171
+ #
172
+ # @example
173
+ # minds.destroy('old_assistant')
174
+ #
151
175
def destroy ( name )
152
176
@client . delete ( path : "projects/#{ @project } /minds/#{ name } " )
153
177
end
154
178
155
- # Create a new mind and return it
179
+ ##
180
+ # Creates a new mind
156
181
#
157
182
# @param name [String] The name of the mind
158
183
# @param model_name [String, nil] The LLM model name (optional)
@@ -163,9 +188,21 @@ def destroy(name)
163
188
# - String: name of the datasource
164
189
# - Datasource object (Minds::Datasource)
165
190
# - DatabaseConfig object (Minds::DatabaseConfig), in this case datasource will be created
166
- # @param parameters [Hash, nil] Other parameters of the mind (optional)
167
- # @param replace [Boolean] If true, remove existing mind with the same name (default: false)
168
- # @return [Mind] The created mind object
191
+ # @param [Hash, nil] parameters Additional parameters
192
+ # @param [Boolean] replace Whether to replace existing mind
193
+ # @return [Mind] The created mind
194
+ #
195
+ # @example Simple creation
196
+ # mind = minds.create(name: 'sales_assistant', model_name: 'gpt-4')
197
+ #
198
+ # @example Creation with datasources
199
+ # mind = minds.create(
200
+ # name: 'sales_assistant',
201
+ # model_name: 'gpt-4',
202
+ # datasources: ['sales_db'],
203
+ # prompt_template: 'Analyze sales data: {{question}}'
204
+ # )
205
+ #
169
206
def create ( name :, model_name : nil , provider : nil , prompt_template : nil , datasources : nil , parameters : nil , replace : false )
170
207
if replace
171
208
begin
0 commit comments