1.1.8-mini • Published 12 months ago

synthmind v1.1.8-mini

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

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

  1. Agents: Various AI agent implementations (OpenAI, Azure OpenAI, Groq, Gemini)
  2. Tools: Customizable tools for extending agent capabilities
  3. Memory: Agent memory management system
  4. 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 models
  • AzureOpenAIAgent: Agent implementation using Azure OpenAI models
  • GroqAgent: Agent implementation using Groq models
  • GeminiAgent: Agent implementation using Google's Gemini models
  • defaultTools: Function to create default tools
  • createTool: Function to create custom tools
  • createGeminiTool: Function to create custom tools for Gemini agents
  • AgentMemory: Memory management system for agents
  • embedText: Function to embed text in the MongoDB vector store
  • embeddingRetrieve: Function to retrieve similar documents from the MongoDB vector store
  • ChromaVectorStore: Vector store implementation using Chroma
  • azureEmbedding: 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:

  1. Fork the repository
  2. Create a new branch for your feature or bug fix
  3. Make your changes and commit them with clear, descriptive messages
  4. Push your changes to your fork
  5. Create a pull request to the main repository

Please ensure your code adheres to the existing style and includes appropriate tests and documentation.

1.1.8

12 months ago

1.1.7

12 months ago

1.1.8-mini

12 months ago

1.1.6

12 months ago

1.1.5

12 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago

1.1.1

12 months ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago