Skip to content

Commit 3b76a80

Browse files
committed
update rubydoc
1 parent 3f8dd1f commit 3b76a80

File tree

6 files changed

+108
-22
lines changed

6 files changed

+108
-22
lines changed

lib/minds.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
module Minds
1414
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
1520
def call(env)
1621
@app.call(env)
1722
rescue Faraday::Error => e

lib/minds/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Minds
24
class Client
35
include Minds::RestClient

lib/minds/config/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Minds
24
module Config
35
class Base

lib/minds/datasources.rb

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Datasources
2828
def initialize(client:)
2929
@client = client
3030
end
31+
32+
##
3133
# Create a new datasource and return it
3234
#
3335
# @param ds_config [DatabaseConfig] datasource configuration
@@ -38,6 +40,21 @@ def initialize(client:)
3840
# @option ds_config [Array<String>] :tables (optional) List of allowed tables
3941
# @param replace [Boolean] If true, replaces an existing datasource with the same name
4042
# @return [Datasource] The created datasource object
43+
# @raise [ObjectNotSupported] If datasource type is not supported
44+
#
45+
# @example
46+
# config = DatabaseConfig.new(
47+
# name: 'sales_db',
48+
# engine: 'postgres',
49+
# connection_data: {
50+
# host: 'localhost',
51+
# port: 5432,
52+
# user_name: "test"
53+
# password: "test"
54+
# }
55+
# )
56+
# datasource = datasources.create(config)
57+
#
4158
def create(ds_config, replace = false)
4259
name = ds_config.name
4360
if replace
@@ -50,9 +67,15 @@ def create(ds_config, replace = false)
5067
find(name)
5168
end
5269

53-
# Returns a list of all datasources
70+
##
71+
# Returns a list of datasources
5472
#
5573
# @return [Array<Datasource>] An array of Datasource objects
74+
#
75+
# @example
76+
# datasources = datasources.all
77+
# datasources.each { |ds| puts ds.name }
78+
#
5679
def all
5780
data = @client.get(path: "datasources")
5881
return [] if data.empty?
@@ -64,11 +87,17 @@ def all
6487
end
6588
end
6689

67-
# Get a datasource by name
90+
##
91+
# Find a datasource by name
6892
#
6993
# @param name [String] The name of the datasource to find
7094
# @return [Datasource] The found datasource object
7195
# @raise [ObjectNotSupported] If the datasource type is not supported
96+
#
97+
# @example
98+
# datasource = datasources.find('sales_db')
99+
# puts datasource.engine
100+
#
72101
def find(name)
73102
data = @client.get(path: "datasources/#{name}")
74103
if data["engine"].nil?
@@ -77,10 +106,19 @@ def find(name)
77106
Datasource.new(**data.transform_keys(&:to_sym))
78107
end
79108

80-
# Destroy (delete) a datasource by name
109+
##
110+
# Deletes a datasource
111+
#
112+
# @param name [String] Datasource name to delete
113+
# @param force [Boolean] Whether to force delete from all minds
114+
#
115+
# @example
116+
# # Simple delete
117+
# datasources.destroy('old_db')
118+
#
119+
# # Force delete
120+
# datasources.destroy('old_db', force: true)
81121
#
82-
# @param name [String] The name of the datasource to delete
83-
# @param force: if true -remove from all minds, default: false
84122
def destroy(name, force: false)
85123
data = force ? { cascade: true } : nil
86124
@client.delete(path: "datasources/#{name}", parameters: data)

lib/minds/minds.rb

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require "openai"
24
require "uri"
35

@@ -20,7 +22,8 @@ def initialize(client, attributes = {})
2022
@datasources = attributes["datasources"]
2123
end
2224

23-
# Update the mind with new parameters
25+
##
26+
# Update mind
2427
#
2528
# @param name [String, nil] New name of the mind (optional)
2629
# @param model_name [String, nil] New LLM model name (optional)
@@ -29,8 +32,8 @@ def initialize(client, attributes = {})
2932
# @param datasources [Array<String, Datasource, DatabaseConfig>, nil] Alter list of datasources used by mind (optional)
3033
# Datasource can be passed as:
3134
# - 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
3437
# @param parameters [Hash, nil] Alter other parameters of the mind (optional)
3538
# @return [void]
3639
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
5457
@name = name if name && name != @name
5558
end
5659

57-
# Add a datasource to the mind
60+
##
61+
# Add datasource to mind
5862
#
59-
# @param datasource [String, Datasource, DatabaseConfig] The datasource to add
63+
# @param datasource [String, Datasource, DatabaseConfig] Datasource to add
6064
# Can be passed as:
6165
# - 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
6468
# @return [void]
6569
def add_datasources(datasource)
6670
ds_name = @client.minds.check_datasource(datasource)
@@ -71,13 +75,15 @@ def add_datasources(datasource)
7175
@datasources = mind.datasources
7276
end
7377

74-
# Delete a datasource from the mind
78+
##
79+
# Remove datasource from mind
7580
#
76-
# @param datasource [String, Datasource] The datasource to delete
81+
# @param datasource [String, Datasource] Datasource to remove
7782
# Can be passed as:
7883
# - String: name of the datasource
7984
# - Datasource object (Minds::Resources::Datasource)
8085
# @return [void]
86+
# @raise [ArgumentError] If datasource type is invalid
8187
def destroy_datasources(datasource)
8288
if datasource.is_a?(Datasource)
8389
datasource = datasource.name
@@ -90,6 +96,7 @@ def destroy_datasources(datasource)
9096
@datasources = mind.datasources
9197
end
9298

99+
##
93100
# Call mind completion
94101
#
95102
# @param message [String] The input question or prompt
@@ -125,34 +132,52 @@ def initialize(client:)
125132
@project = "mindsdb"
126133
end
127134

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 }
129143
#
130-
# @return [Array<Mind>] An array of Mind objects
131144
def all
132145
data = @client.get(path: "projects/#{@project}/minds")
133146
return [] if data.empty?
134147

135148
data.map { |item| Mind.new(@client, item) }
136149
end
137150

138-
# Get a mind by name
151+
##
152+
# Find a mind by name
139153
#
140154
# @param name [String] The name of the mind to find
141155
# @return [Mind] The found mind object
156+
#
157+
# @example
158+
# mind = minds.find('sales_assistant')
159+
# puts mind.model_name
160+
#
142161
def find(name)
143162
data = @client.get(path: "projects/#{@project}/minds/#{name}")
144163
Mind.new(@client, data)
145164
end
146165

147-
# Drop (delete) a mind by name
166+
##
167+
# Deletes a mind
148168
#
149169
# @param name [String] The name of the mind to delete
150170
# @return [void]
171+
#
172+
# @example
173+
# minds.destroy('old_assistant')
174+
#
151175
def destroy(name)
152176
@client.delete(path: "projects/#{@project}/minds/#{name}")
153177
end
154178

155-
# Create a new mind and return it
179+
##
180+
# Creates a new mind
156181
#
157182
# @param name [String] The name of the mind
158183
# @param model_name [String, nil] The LLM model name (optional)
@@ -163,9 +188,21 @@ def destroy(name)
163188
# - String: name of the datasource
164189
# - Datasource object (Minds::Datasource)
165190
# - 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+
#
169206
def create(name:, model_name: nil, provider: nil, prompt_template: nil, datasources: nil, parameters: nil, replace: false)
170207
if replace
171208
begin

lib/minds/rest_client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Minds
24
module RestClient
35
def get(path:)

0 commit comments

Comments
 (0)