synthmind v1.1.8-mini
SynthMind
SynthMind is a powerful and flexible library for creating and interacting with AI agents using various models and tools. It provides a comprehensive framework for building intelligent applications with features such as memory management, custom tools, and vector-based knowledge retrieval.
Table of Contents
Installation
To install SynthMind, use the following command:
npm install synthmind
Make sure you have Node.js and npm installed on your system.
Key Components
- Agents: Various AI agent implementations (OpenAI, Azure OpenAI, Groq, Gemini)
- Tools: Customizable tools for extending agent capabilities
- Memory: Agent memory management system
- Vector Store: Embedding and retrieval of vector-based knowledge (MongoDB and Chroma)
Usage
Setting up the environment
First, set up your environment variables in a .env
file:
MONGODB_URI=your_mongodb_uri
OPENAI_API_KEY=your_openai_api_key
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_ENDPOINT=your_azure_openai_base_url
GROQ_API_KEY=your_groq_api_key
GEMINI_API_KEY=your_gemini_api_key
CHROMA_COLLECTION_NAME=your_chroma_collection_name
Importing required modules
import {
OpenAIAgent,
AzureOpenAIAgent,
GroqAgent,
GeminiAgent,
defaultTools,
createTool,
AgentMemory,
embedText,
embeddingRetrieve,
createGeminiTool,
ChromaVectorStore,
azureEmbedding
} from "synthmind";
Creating custom tools
You can create custom tools using the createTool
function:
const customTool = createTool({
tool_name: "custom_tool",
description: "A custom tool description",
parameters: {
type: "object",
properties: {
param1: { type: "string", description: "First parameter" },
param2: { type: "number", description: "Second parameter" },
},
required: ["param1"],
},
tool_function: (query) => {
// Implement tool functionality here
return `Processed: ${query.param1}, ${query.param2}`;
},
});
Initializing agents
You can initialize different types of agents:
OpenAI Agent
const openaiAgent = new OpenAIAgent({
systemMessage: "You are a helpful AI assistant named David.",
tools: tools,
apiKey: process.env.OPENAI_API_KEY,
memory: true,
});
Azure OpenAI Agent
const azureAgent = new AzureOpenAIAgent({
systemMessage: "You are a helpful AI assistant specialized in Azure services.",
tools: tools,
apiKey: process.env.AZURE_OPENAI_API_KEY,
endpoint: process.env.AZURE_ENDPOINT,
apiVersion: "2023-03-15-preview",
deployment: "gpt-4o",
memory: true,
});
Groq Agent
const groqAgent = new GroqAgent({
systemMessage: "You are a fast and efficient AI assistant.",
tools: tools,
apiKey: process.env.GROQ_API_KEY,
memory: true,
});
Gemini Agent
const geminiAgent = new GeminiAgent({
systemMessage: "You are an AI assistant powered by Google's Gemini model.",
tools: tools,
apiKey: process.env.GEMINI_API_KEY,
memory: true,
});
Sending messages to an agent
const response = await agent.sendMessage("Your message here");
console.log(response);
Using the vector store
The library includes functions for embedding text and retrieving similar documents:
// Embed text in the vector store
await embedText({
content: "Text to be embedded",
dbUri: process.env.MONGODB_URI,
openAIApiKey: process.env.OPENAI_API_KEY,
});
// Retrieve similar documents
const documents = await embeddingRetrieve({
query: "Your search query",
dbUri: process.env.MONGODB_URI,
openAIApiKey: process.env.OPENAI_API_KEY,
});
Using memory
The library includes a memory management system:
AgentMemory.addMessage({
userMessage: "User input",
agentMessage: "Agent response",
});
const messages = AgentMemory.getMessages();
Advanced Features
Chroma Vector Store
SynthMind now supports Chroma as a vector store:
const store = new ChromaVectorStore("my-collection", {
azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
azureOpenAIApiEmbeddingsDeploymentName: process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME,
azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,
});
await store.initialize();
await store.addDocuments("Your text here");
const results = await store.similaritySearch("Your query here", 2);
Azure Embedding
SynthMind now supports Azure OpenAI embeddings:
const azureEmbeddingModel = azureEmbedding({
azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
azureOpenAIApiEmbeddingsDeploymentName: process.env.AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME,
azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,
});
Gemini Agent and Tools
SynthMind now includes support for Google's Gemini model:
const geminiTool = createGeminiTool({
tool_name: "gemini_tool",
description: "A custom tool for Gemini agent",
parameters: {
type: "object",
properties: {
query: { type: "string", description: "Input for the Gemini tool" },
},
required: ["query"],
},
tool_function: async (query) => {
// Implement Gemini-specific functionality here
},
});
API Reference
The SynthMind library exports the following main components:
OpenAIAgent
: Agent implementation using OpenAI modelsAzureOpenAIAgent
: Agent implementation using Azure OpenAI modelsGroqAgent
: Agent implementation using Groq modelsGeminiAgent
: Agent implementation using Google's Gemini modelsdefaultTools
: Function to create default toolscreateTool
: Function to create custom toolscreateGeminiTool
: Function to create custom tools for Gemini agentsAgentMemory
: Memory management system for agentsembedText
: Function to embed text in the MongoDB vector storeembeddingRetrieve
: Function to retrieve similar documents from the MongoDB vector storeChromaVectorStore
: Vector store implementation using ChromaazureEmbedding
: Function to create Azure OpenAI embeddings
For detailed API documentation, please refer to the inline code comments and type definitions.
Error Handling
SynthMind uses async/await patterns for most operations. It's recommended to use try-catch blocks when calling asynchronous functions:
try {
const response = await agent.sendMessage("Your message here");
console.log(response);
} catch (error) {
console.error("An error occurred:", error);
}
Limitations
- The library currently supports a limited set of AI models (OpenAI, Azure OpenAI, Groq, and Gemini).
- Vector store operations require either a MongoDB instance or a Chroma server.
- Some features may require specific API keys or access to certain services.
Contributing
Contributions to SynthMind are welcome! Please follow these steps to contribute:
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes and commit them with clear, descriptive messages
- Push your changes to your fork
- Create a pull request to the main repository
Please ensure your code adheres to the existing style and includes appropriate tests and documentation.
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago