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
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.
AI-Kit is available as an NPM package that can be easily integrated into your TypeScript or JavaScript projects.
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)
# Using npm
npm install @sola-labs/ai-kit
# Using yarn
yarn add @sola-labs/ai-kit
# Using pnpm
pnpm add @sola-labs/ai-kitAI-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.0Below 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
}
}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);
}AI-Kit includes the following toolsets:
-
Token Toolset (
tokenToolSetFactory)- Features: Get token data, resolve token addresses, fetch top holders, get limit orders, etc.
- Example:
getTokenDatatool returns detailed information about any token on Solana.
-
NFT Toolset (
nftToolSetFactory)- Features: Get NFT prices, find trending NFT collections
- Example:
getTrendingNFTstool returns a list of currently popular NFT collections.
-
Lulo Toolset (
luloToolSetFactory)- Features: Get Lulo assets, deposit and withdraw from Lulo (a decentralized exchange on Solana)
- Example:
getLuloAssetstool returns user's assets and earnings on the Lulo platform.
-
OnChain Toolset (
onChainToolSetFactory)- Features: Resolve SNS names, swap tokens, transfer SOL and SPL tokens
- Example:
transferSolTxtool allows creating and signing SOL transfer transactions.
-
AI Projects Toolset (
aiProjectsToolSetFactory)- Features: Filter and find trending AI projects on Solana
- Example:
filterTrendingAiProjectsToolprovides information about popular AI-related projects.
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],
});- 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.
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
See the CONTRIBUTING.md file for more details on our development workflow.
Distributed under the GPL-3.0 License. See LICENSE for more information.
Sola AI - @SolaAI
Project Link: https://github.com/TheSolaAI/ai-kit
- Vercel AI SDK Team
- Solana Foundation
- OpenAI
- All contributors to this project
