0.0.1 • Published 5 months ago
@dixitt5/ai v0.0.1
Incubyte-AI
A flexible and powerful chat library for building AI-powered conversational applications with contextual understanding and document retrieval capabilities.
✨ Features
- 🤖 AI-powered chat with deep context understanding
- 📄 Document retrieval from vector stores (RAG)
- 🔁 Streaming responses for real-time interaction
- 🔗 Seamless integration with LangChain and OpenAI
- 💾 Checkpoint saving for persistent conversations
📦 Installation
npm install @incubyte/ai
🚀 Usage
Basic Example
import { Chat } from "@incubyte/ai";
// Initialize Chat
const chat = new Chat();
// Send a message and get a response
const response = await chat.sendChat("tenant-id", "conversation-id", {
query: "What is the best way to lose weight?",
});
console.log(response);
Streaming Example
import { Chat } from "@incubyte/ai";
// Initialize Chat
const chat = new Chat();
// Stream a chat conversation
const stream = await chat.sendChatStream("tenant-id", "conversation-id", {
query: "Tell me about intermittent fasting",
});
// Process the stream
for await (const chunk of stream) {
if (chunk.type === "message") {
console.log(chunk.data.content);
} else if (chunk.type === "context") {
console.log("Retrieved context:", chunk.data);
}
}
API Reference
Chat
Class
The main class for interacting with the chat system.
Constructor
new Chat(checkpointSaverManager?: BaseCheckpointSaver)
checkpointSaverManager
(optional): An instance ofBaseCheckpointSaver
from@langchain/langgraph
for saving chat state checkpoints.
Methods
sendChat
async sendChat(
tenantId: string,
conversationId: string,
chatRequestDto: ChatRequestDto
): Promise<{ chatResponse: StateType<GraphStateAnnotation> }>
Sends a chat message and returns a structured response.
tenantId
: Identifier for the tenant or knowledge baseconversationId
: Unique identifier for the conversationchatRequestDto
: Object with the following structure:
{
query: string;
metadataFilters?: Record<string, string | string[]>[];
}
sendChatStream
async sendChatStream(
tenantId: string,
conversationId: string,
chatRequestDto: ChatRequestDto
): AsyncGenerator<StreamResponse>
Sends a chat message and returns a stream of response chunks.
tenantId
: Identifier for the tenant or knowledge baseconversationId
: Unique identifier for the conversationchatRequestDto
: Same structure as above
✅ Requirements
Node.js 16 or above
TypeScript or JavaScript project compatibility
License
ISC License
0.0.1
5 months ago