This SDK provides a JavaScript interface to interact with MindsDB, allowing you to manage minds, datasources, and perform queries. The SDK handles API interactions, error handling, and provides an easy-to-use interface for creating, listing, updating, and deleting minds and datasources.
To install the SDK, use npm:
npm install mindsdb-sdk
const Client = require('mindsdb-sdk');
// Initialize the client
const client = new Client('YOUR_API_KEY');
const mind = await client.minds.create('my_mind', {
modelName: 'gpt-3',
provider: 'OpenAI',
datasources: ['datasource1', 'datasource2'],
promptTemplate: 'You are a coding assistant',
});
const minds = await client.minds.list();
console.log(minds);
const mind = await client.minds.get('my_mind');
await client.minds.drop('my_mind');
const datasourceConfig = {
name: 'my_datasource',
engine: 'postgres',
description: 'Sample Postgres datasource',
connectionData: {
user: 'demo_user',
password: 'demo_password',
host: 'samples.mindsdb.com',
port: 5432,
database: 'demo',
schema: 'demo_data',
},
tables: ['table1', 'table2'],
};
const datasource = await client.datasources.create(datasourceConfig);
const datasources = await client.datasources.list();
console.log(datasources);
const datasource = await client.datasources.get('my_datasource');
await client.datasources.drop('my_datasource');
The SDK includes built-in error handling. Common error types are:
-
ObjectNotFound: Thrown when a resource (mind or datasource) cannot be found.
-
Forbidden: Thrown for a
403
Forbidden response. -
Unauthorized: Thrown for a
401
Unauthorized response. -
UnknownError: Thrown for any other unhandled errors.
try {
const mind = await client.minds.get('non_existent_mind');
} catch (error) {
if (error instanceof ObjectNotFound) {
console.error('Mind not found');
}
}
-
Client(apiKey, baseUrl)
: Initializes the SDK client. -
apiKey
: Your MindsDB API key. -
baseUrl
: Optional base URL for custom MindsDB instances.
-
client.minds.create(name, options)
: Creates a new mind. -
client.minds.list()
: Lists all minds. -
client.minds.get(name)
: Retrieves a mind by name. -
client.minds.drop(name)
: Deletes a mind.
-
client.datasources.create(config, replace = false)
: Creates a new datasource. -
client.datasources.list()
: Lists all datasources. -
client.datasources.get(name)
: Retrieves a datasource by name. -
client.datasources.drop(name)
: Deletes a datasource.