
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
@push.rocks/smartai
Advanced tools
SmartAi is a versatile TypeScript library designed to facilitate integration and interaction with various AI models, offering functionalities for chat, audio generation, document processing, and vision tasks.
SmartAi is a TypeScript library providing a unified interface for integrating and interacting with multiple AI models, supporting chat interactions, audio and document processing, and vision tasks.
To install SmartAi into your project, you need to run the following command in your terminal:
npm install @push.rocks/smartai
This command will add the SmartAi library to your project's dependencies, making it available for use in your TypeScript application.
SmartAi is designed to provide a comprehensive and unified API for working seamlessly with multiple AI providers like OpenAI, Anthropic, Perplexity, and others. Below we will delve into how to make the most out of this library, illustrating the setup and functionality with in-depth examples. Our scenarios will explore synchronous and streaming interactions, audio generation, document handling, and vision tasks with different AI providers.
Initialization is the first step before using any AI functionalities. You should provide API tokens for each provider you plan to utilize.
import { SmartAi } from '@push.rocks/smartai';
const smartAi = new SmartAi({
openaiToken: 'your-openai-token',
anthropicToken: 'your-anthropic-token',
perplexityToken: 'your-perplexity-token',
xaiToken: 'your-xai-token',
groqToken: 'your-groq-token',
ollama: {
baseUrl: 'http://localhost:11434',
model: 'llama2',
visionModel: 'llava'
},
exo: {
baseUrl: 'http://localhost:8080/v1',
apiKey: 'your-api-key'
}
});
await smartAi.start();
Interaction through chat is a key feature. SmartAi caters to both synchronous and asynchronous (streaming) chats across several AI models.
Connect with AI models via straightforward request-response interactions.
const syncResponse = await smartAi.openaiProvider.chat({
systemMessage: 'You are a helpful assistant.',
userMessage: 'What is the capital of France?',
messageHistory: [] // Could include context or preceding messages
});
console.log(syncResponse.message); // Outputs: "The capital of France is Paris."
For continuous interaction and lower latency, engage in streaming chat.
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
// Establish a transform stream
const { writable, readable } = new TransformStream();
const writer = writable.getWriter();
const message = {
role: 'user',
content: 'Tell me a story about a brave knight'
};
writer.write(textEncoder.encode(JSON.stringify(message) + '\n'));
// Initiate streaming
const stream = await smartAi.openaiProvider.chatStream(readable);
const reader = stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log('AI:', value);
}
Audio generation from textual input is possible using providers like OpenAI.
const audioStream = await smartAi.openaiProvider.audio({
message: 'This is a test message for generating speech.'
});
// Use the audioStream e.g., playing or saving it.
SmartAi can ingest and process documents, extracting meaningful information or performing classifications.
const pdfBuffer = await fetchPdf('https://example.com/document.pdf');
const documentRes = await smartAi.openaiProvider.document({
systemMessage: 'Determine the nature of the document.',
userMessage: 'Classify this document.',
messageHistory: [],
pdfDocuments: [pdfBuffer]
});
console.log(documentRes.message); // Outputs: classified document type
SmartAi allows easy switching between providers, thus giving developers flexibility:
const anthopicRes = await smartAi.anthropicProvider.document({
systemMessage: 'Analyze this document.',
userMessage: 'Extract core points.',
messageHistory: [],
pdfDocuments: [pdfBuffer]
});
console.log(anthopicRes.message); // Outputs: summarized core points
Engage AI models in analyzing and describing images:
const imageBuffer = await fetchImage('path/to/image.jpg');
// Using OpenAI's vision capabilities
const visionOutput = await smartAi.openaiProvider.vision({
image: imageBuffer,
prompt: 'Describe the image.'
});
console.log(visionOutput); // Outputs: image description
Use other providers for more varied analysis:
const ollamaOutput = await smartAi.ollamaProvider.vision({
image: imageBuffer,
prompt: 'Detailed analysis required.'
});
console.log(ollamaOutput); // Outputs: detailed analysis results
Due to the nature of external integrations, ensure to wrap AI calls within try-catch blocks.
try {
const response = await smartAi.anthropicProvider.chat({
systemMessage: 'Hello!',
userMessage: 'Help me out.',
messageHistory: []
});
console.log(response.message);
} catch (error: any) {
console.error('Encountered an error:', error.message);
}
The library supports provider-specific customization, enabling tailored interactions:
const smartAi = new SmartAi({
openaiToken: 'your-openai-token',
anthropicToken: 'your-anthropic-token',
ollama: {
baseUrl: 'http://localhost:11434',
model: 'llama2',
visionModel: 'llava'
}
});
await smartAi.start();
Developers can implement real-time processing pipelines with custom transformations:
const customProcessingStream = new TransformStream({
transform(chunk, controller) {
const processed = chunk.toUpperCase(); // Example transformation
controller.enqueue(processed);
}
});
const processedStream = stream.pipeThrough(customProcessingStream);
const processedReader = processedStream.getReader();
while (true) {
const { done, value } = await processedReader.read();
if (done) break;
console.log('Processed Output:', value);
}
This approach can facilitate adaptive content processing workflows.
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
FAQs
SmartAi is a versatile TypeScript library designed to facilitate integration and interaction with various AI models, offering functionalities for chat, audio generation, document processing, and vision tasks.
The npm package @push.rocks/smartai receives a total of 28 weekly downloads. As such, @push.rocks/smartai popularity was classified as not popular.
We found that @push.rocks/smartai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.