npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minds_js_sdk

v1.0.8

Published

JavaScript SDK for Minds AI

Downloads

578

Readme

MindsDB JavaScript SDK

This SDK provides an interface to interact with the MindsDB API. It allows you to create and manage "minds" (AI models) and data sources.

Installation

npm install mindsdb_js_sdk

Configuration

The SDK uses environment variables or constructor parameters for configuration:

import Client from 'mindsdb_js_sdk';

// Default configuration (uses MINDS_API_KEY env variable and staging URL)
const client = new Client();

// Optional: Specify custom API key and base URL
const client = new Client('your_api_key', 'https://custom.mdb.ai');

Managing Data Sources

Creating a Data Source

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 datasource
try {
  const datasource = await client.datasources.create(datasourceConfig);
  console.log('Datasource created:', datasource);
} catch (error) {
  console.error('Error creating datasource:', error);
}

// Create or replace existing datasource
try {
  const datasource = await client.datasources.create(datasourceConfig, true);
  console.log('Datasource created/replaced:', datasource);
} catch (error) {
  console.error('Error creating/replacing datasource:', error);
}

Listing Data Sources

try {
  const datasources = await client.datasources.list();
  console.log('Available datasources:', datasources);
} catch (error) {
  console.error('Error listing datasources:', error);
}

Getting a Data Source

try {
  const datasource = await client.datasources.get('my_postgres_db');
  console.log('Datasource details:', datasource);
} catch (error) {
  console.error('Error getting datasource:', error);
}

Deleting a Data Source

try {
  await client.datasources.drop('my_postgres_db');
  console.log('Datasource deleted');
} catch (error) {
  console.error('Error deleting datasource:', error);
}

Managing Minds

Creating a Mind

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);
}

Listing Minds

try {
  const minds = await client.minds.list();
  console.log('Available minds:', minds);
} catch (error) {
  console.error('Error listing minds:', error);
}

Getting a Mind

try {
  const mind = await client.minds.get('my_mind');
  console.log('Mind details:', mind);
} catch (error) {
  console.error('Error getting mind:', error);
}

Deleting a Mind

try {
  await client.minds.drop('my_mind');
  console.log('Mind deleted');
} catch (error) {
  console.error('Error deleting mind:', error);
}

Using a Mind for Completion

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);
}

Error Handling

The SDK uses custom error classes for specific error scenarios:

  • ObjectNotFound: Thrown when a requested resource doesn't exist
  • ObjectNotSupported: Thrown for unsupported datasource types
  • Forbidden: Thrown for permission-related issues
  • Unauthorized: Thrown for authentication problems
  • UnknownError: Thrown for unclassified errors
import { ObjectNotFound, ObjectNotSupported } from 'mindsdb_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);
  }
}

Notes

  • 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 'mindsdb'

License

This project is licensed under the MIT License.