Skip to content

TheSolaAI/ai-kit

Repository files navigation

Contributors Forks Stargazers Issues Unlicense License


Logo

AI-Kit

Forge your own intelligent AI agents using the core tools and workflows that power Sola AI.
Explore the docs »

View Demo · Report Bug

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Documentation
  5. Roadmap
  6. Contributing
  7. License
  8. Contact
  9. Acknowledgments

About The Project

AI-Kit

Through the development of Sola AI, our flagship voice assistant on the Solana blockchain, we've pioneered a suite of custom implementations and tooling that intricately weave AI LLM's with the crypto and blockchain landscape. Recognizing the broader utility of these solutions, we are now sharing this library with fellow developers. Our aim is to fuel the Solana AI ecosystem, enabling you to seamlessly integrate the very tools that empower Sola AI within your own innovative projects. This library represents the heart and hard-won efficiencies derived from numerous iterations, ensuring both precision and performance.

(back to top)

Built With

(back to top)

Getting Started

AI-Kit is available as an NPM package that can be easily integrated into your TypeScript or JavaScript projects.

Prerequisites

AI-Kit is designed to work with Node.js projects. It has peer dependencies that you'll need to install.

  • Node.js (v16 or higher)
  • npm or yarn
  • An OpenAI API key (for some toolsets)

Installation

# Using npm
npm install @sola-labs/ai-kit

# Using yarn
yarn add @sola-labs/ai-kit

# Using pnpm
pnpm add @sola-labs/ai-kit

AI-Kit requires the following peer dependencies:

# Using npm
npm install ai@^4.0.0 @ai-sdk/openai@^1.0.0

# Using yarn
yarn add ai@^4.0.0 @ai-sdk/openai@^1.0.0

# Using pnpm
pnpm add ai@^4.0.0 @ai-sdk/openai@^1.0.0

(back to top)

Usage

Basic Usage

Below is a minimal example of how to use AI-Kit to create an AI agent:

import { SolaKit } from '@sola-labs/ai-kit';
import { OpenAILanguageModel } from '@ai-sdk/openai';

// Initialize the language model
const model = new OpenAILanguageModel({
  apiKey: process.env.OPENAI_API_KEY,
});

// Create a new SolaKit instance
const solaKit = new SolaKit({
  model,
  systemPrompt: 'You are a helpful assistant.',
  toolSetFactories: [], // Empty array for no toolsets initially
});

// Process a user query
async function processQuery(userInput: string) {
  const response = await solaKit.query({
    prompt: userInput,
  });

  console.log(response);
}

// Stream text responses (useful for UI applications)
async function streamResponse(userInput: string) {
  const stream = solaKit.streamText({
    prompt: userInput,
  });

  for await (const chunk of stream) {
    console.log(chunk); // Process each text chunk as it arrives
  }
}

Using Toolsets

AI-Kit comes with several pre-built toolsets that you can use. Here's how to use them:

import { SolaKit } from '@sola-labs/ai-kit';
import { OpenAILanguageModel } from '@ai-sdk/openai';
import { tokenToolSetFactory, nftToolSetFactory } from '@sola-labs/ai-kit/sola';

// Initialize the language model
const model = new OpenAILanguageModel({
  apiKey: process.env.OPENAI_API_KEY,
});

// Create a SolaKit instance with toolsets
const solaKit = new SolaKit({
  model,
  systemPrompt:
    'You are a helpful assistant with knowledge about Solana tokens and NFTs.',
  toolSetFactories: [tokenToolSetFactory, nftToolSetFactory],
});

// Process a query with specific toolsets
async function processTokenQuery(userInput: string) {
  const response = await solaKit.query({
    prompt: userInput,
    toolSets: ['token'], // Only use the token toolset for this query
    toolsContext: {
      authToken: 'your-auth-token', // Required by some tools
      walletPublicKey: 'your-wallet-public-key',
      apiClient: yourApiClientInstance, // Optional custom API client
    },
  });

  console.log(response);
}

(back to top)

Documentation

Available Toolsets

AI-Kit includes the following toolsets:

  1. Token Toolset (tokenToolSetFactory)

    • Features: Get token data, resolve token addresses, fetch top holders, get limit orders, etc.
    • Example: getTokenData tool returns detailed information about any token on Solana.
  2. NFT Toolset (nftToolSetFactory)

    • Features: Get NFT prices, find trending NFT collections
    • Example: getTrendingNFTs tool returns a list of currently popular NFT collections.
  3. Lulo Toolset (luloToolSetFactory)

    • Features: Get Lulo assets, deposit and withdraw from Lulo (a decentralized exchange on Solana)
    • Example: getLuloAssets tool returns user's assets and earnings on the Lulo platform.
  4. OnChain Toolset (onChainToolSetFactory)

    • Features: Resolve SNS names, swap tokens, transfer SOL and SPL tokens
    • Example: transferSolTx tool allows creating and signing SOL transfer transactions.
  5. AI Projects Toolset (aiProjectsToolSetFactory)

    • Features: Filter and find trending AI projects on Solana
    • Example: filterTrendingAiProjectsTool provides information about popular AI-related projects.

Creating Custom Toolsets

You can create your own toolsets that integrate with AI-Kit:

import {
  createToolSetFactory,
  createToolFactory,
} from '@sola-labs/ai-kit/tools';
import { z } from 'zod';

// Define a tool factory
const myCustomToolFactory = createToolFactory(
  {
    description: 'Description of what my custom tool does',
    parameters: z.object({
      param1: z.string().describe('Description of parameter 1'),
      param2: z.number().optional().describe('Optional numeric parameter'),
    }),
  },
  async (params, context) => {
    // Implement your tool logic here
    const result = await someAsyncOperation(params.param1, params.param2);

    return {
      success: true,
      data: result,
      error: undefined,
    };
  }
);

// Create a toolset factory that includes your tool
export const myCustomToolSetFactory = createToolSetFactory(
  {
    slug: 'custom',
    name: 'Custom Tools',
    description: 'A collection of custom tools for specific purposes.',
  },
  {
    myCustomTool: myCustomToolFactory,
  }
);

// Use your custom toolset in SolaKit
const solaKit = new SolaKit({
  model,
  systemPrompt: 'You are a helpful assistant.',
  toolSetFactories: [myCustomToolSetFactory],
});

(back to top)

Roadmap

  • Add more documentation and examples
  • Create plugin system for easy extension
  • Improve error handling and debugging
  • Add support for more language models
  • Build a comprehensive test suite
  • Create additional toolsets for DeFi applications

See the open issues for a list of proposed features and known issues.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

See the CONTRIBUTING.md file for more details on our development workflow.

Top contributors:

contrib.rocks image

(back to top)

License

Distributed under the GPL-3.0 License. See LICENSE for more information.

(back to top)

Contact

Sola AI - @SolaAI

Project Link: https://github.com/TheSolaAI/ai-kit

(back to top)

Acknowledgments

(back to top)

About

AI KIT powering SOLA

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors