data operations library for e-llm-studio
npm install @e-llm-studio/data-engineWelcome to the eLLM Studio Data Operations package! 🎉 This package enables streaming chat functionality with your AI assistant in eLLM Studio via WebSocket and GraphQL. It's designed for both frontend and backend implementations.
- Data Ingestion: Ingest text data.
``bash`
npm i @e-llm-studio/data-engine
Here’s how you can use the startChatStream function to set up the AI chat stream:
`typescript
import { ContentManager } from "@e-llm-studio/data-engine";
// Example usage:
const baseUrl = "https://dev-egpt.techo.camp";
const chatbotId = "3e94587c-733d-4e92-8d98-d5150c63b8cd";
const chatbotName = "Assistant1";
const organizationName = "techolution";
const username = "your-username";
const password = "your-password";
const contentManager = new ContentManager(
baseUrl,
chatbotId,
chatbotName,
organizationName,
username,
password
);
// Save text content example
contentManager
.saveTextContent("Title1", "Text Content")
.then((saveResponse) => {
console.log("Save Response:", saveResponse);
})
.catch((error) => {
console.error("Save Error:", error);
});
// Save text file content example
contentManager
.ingestTextFiles("File", "Text File Content")
.then((saveResponse) => {
console.log("Save Response:", saveResponse);
})
.catch((error) => {
console.error("Save Error:", error);
});
// For AccessToken
// Delete text content example
contentManager
.deleteTextContent(["671a391fbcce6ddc80e86099"])
.then((deleteResponse) => {
console.log("Delete Response:", deleteResponse);
})
.catch((error) => {
console.error("Delete Error:", error);
});
// Get Context Id
contentManager
.getContextId("6d25ddb4-e375-4adf-a98d-4d14114c2840")
.then((contextResponse) => {
console.log("Context Response:", contextResponse);
})
.catch((error) => {
console.error("Context Error:", error);
});
// Seamantic Search api
contentManager
.getSemanticSearch(
"model-name", // AI Model to use for semantic search
"search query", // The query string for searching
"request123", // Unique request ID for tracking
"user456", // User ID performing the search
0, // Offset for pagination
10 // Limit for pagination
)
.then((searchResponse) => {
console.log("Search Response:", searchResponse);
})
.catch((error) => {
console.error("Search Error:", error);
});
contentManager.ingestTextFilesText(
{
"contexts": [
{
"contentType": "local_file",
"files": [
{
"id": uuid(),
"name": "file name.txt",
"size": "file size",
"content": "file text content",
"createdTime": "2025-02-05T15:44:06.024Z",
"modifiedTime": "2025-02-05T15:44:06.024Z",
"mimeType": "text/plain"
}
],
"id": uuid()
}
],
"chatbotId": "chatBotId / assistant id "
}).then((context) => {
console.log("Ingestion Successful", ingestedData);
})
.catch((error) => {
console.error("Failed to save text content:", error);
});
``
📝 API Documentation
saveTextContent(title: string, textContent: string): Promise
Saves the provided text content under the specified title.
Parameters:
title (string): The title of the text content.
textContent (string): The content text to be saved.
deleteTextContent(contextInfoIds: string[]): Promise
Deletes the specified content using the provided array of contextInfoIds.
Parameters:
contextInfoIds (string[]): An array of IDs representing the content items to delete.
deleteContextId(fileId: string): Promise
Deletes a specific content item by its fileId.
Parameters:
fileId (string): The ID of the content item to delete from the chatbot’s context.
🔐 Authentication
The package requires user authentication. The ContentManager class will automatically log in using the provided credentials and manage access tokens internally.
Semantic Search
The getSemanticSearch method performs a semantic search based on a provided query and model, returning results from the chatbot’s knowledge base.
async ingestTextFiles(files: File[]): Promise
Processes and uploads plain text files, extracts content, and saves it to the chatbot’s context.
Parameters:
files (File[]): An array of text files to be ingested.
Returns:
A promise that resolves with IContextInfo on success or void if no valid text files are found.
async ensureLoggedIn(): Promise
Ensures that the user is logged in by checking the access token. If no token is present, it attempts to log in.
Returns:
A promise that resolves with the access token if login is successful.
Parameters:
aiModel (string): The name of the AI model to use for the search.
searchQuery (string): The search query string.
requestId (string): A unique identifier for tracking the search request.
userId (string): The ID of the user initiating the search.
offset (number): The number of results to skip (for pagination).
limit (number): The maximum number of results to return.
Returns: A promise that resolves with search results matching the query or an error message if the search fails.
For any questions or issues, feel free to reach out via our GitHub repository or join our community chat! We’re here to help. 😊