This SDK provides an interface to interact with the Minds AI API. It allows you to create and manage "minds" (AI models) and data sources.
npm install minds_js_sdk
The SDK uses environment variables or constructor parameters for configuration:
import MindsClient from 'minds_js_sdk';
// Default configuration (uses MINDS_API_KEY env variable and staging URL)
const client = new MindsClient();
// Optional: Specify custom API key and base URL
const client = new MindsClient('your_api_key', 'https://mdb.ai');
const datasourceConfig = {
name: 'my_postgres_db',
engine: 'postgres',
description: 'My PostgreSQL database',
connection_data: {
host: 'localhost',
port: 5432,
database: 'mydb',
user: 'user',
password: 'password'
},
tables: ['table1', 'table2']
};
// Create a new data source
try {
const datasource = await client.datasources.create(datasourceConfig);
console.log('Data source created:', datasource);
} catch (error) {
console.error('Error creating data source:', error);
}
// Create or replace existing data source
try {
const datasource = await client.datasources.create(datasourceConfig, true);
console.log('Data source created/replaced:', datasource);
} catch (error) {
console.error('Error creating/replacing data source:', error);
}
try {
const datasources = await client.datasources.list();
console.log('Available data sources:', datasources);
} catch (error) {
console.error('Error listing data sources:', error);
}
try {
const datasource = await client.datasources.get('my_postgres_db');
console.log('Data source details:', datasource);
} catch (error) {
console.error('Error getting data source:', error);
}
try {
await client.datasources.drop('my_postgres_db');
console.log('Data source deleted');
} catch (error) {
console.error('Error deleting data source:', error);
}
const mindConfig = {
name: 'my_mind',
model_name: 'gpt-4',
provider: 'openai',
prompt_template: 'Use your database tools to answer the user\'s question: {{question}}',
datasources: ['my_postgres_db'],
parameters: {
// Additional model parameters
}
};
try {
const mind = await client.minds.create('my_mind', mindConfig);
console.log('Mind created:', mind);
} catch (error) {
console.error('Error creating mind:', error);
}
try {
const minds = await client.minds.list();
console.log('Available minds:', minds);
} catch (error) {
console.error('Error listing minds:', error);
}
try {
const mind = await client.minds.get('my_mind');
console.log('Mind details:', mind);
} catch (error) {
console.error('Error getting mind:', error);
}
try {
await client.minds.drop('my_mind');
console.log('Mind deleted');
} catch (error) {
console.error('Error deleting mind:', error);
}
try {
// Synchronous completion
const result = await mind.completion('Your query here');
console.log('Completion result:', result);
// Streaming completion
await mind.completion('Your query here', true);
// This will stream the result to stdout
} catch (error) {
console.error('Error getting completion:', error);
}
The SDK uses custom error classes for specific error scenarios:
ObjectNotFound
: Thrown when a requested resource doesn't existObjectNotSupported
: Thrown for unsupported data source typesForbidden
: Thrown for permission-related issuesUnauthorized
: Thrown for authentication problemsUnknownError
: Thrown for unclassified errors
import { ObjectNotFound, ObjectNotSupported } from 'minds_js_sdk/exception';
try {
const mind = await client.minds.get('non_existent_mind');
} catch (error) {
if (error instanceof ObjectNotFound) {
console.error('Mind not found');
} else if (error instanceof ObjectNotSupported) {
console.error('Unsupported operation');
} else {
console.error('Unexpected error:', error);
}
}
- The default prompt template is: "Use your database tools to answer the user's question: {{question}}"
- The SDK uses OpenAI's client for completions
- The base project is always set to
'minds'
This project is licensed under the MIT License.