
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@kalxjs/ai
Advanced tools
AI integration utilities for KalxJS applications.
# Install latest version
npm install @kalxjs/ai@latest
# Install specific version
npm install @kalxjs/ai@x.x.x
Current version: 1.2.12
import { configure, generateText } from '@kalxjs/ai';
// Configure the AI service
configure({
apiKey: 'your-api-key',
model: 'gpt-3.5-turbo'
});
// Generate text
async function example() {
const response = await generateText('Write a short poem about programming');
console.log(response);
}
example();
import { useAI } from '@kalxjs/ai';
export default {
setup() {
const ai = useAI();
const generateResponse = async () => {
try {
const result = await ai.generate('Explain how JavaScript works in 3 sentences');
console.log(result);
} catch (error) {
console.error('AI generation failed:', error);
}
};
return {
generateResponse,
isLoading: ai.loading(),
error: ai.error(),
result: ai.result()
};
}
};
import { analyzeSentiment, extractEntities, summarize } from '@kalxjs/ai';
async function analyzeText(text) {
// Analyze sentiment
const sentiment = await analyzeSentiment(text);
console.log('Sentiment:', sentiment);
// Extract entities
const entities = await extractEntities(text);
console.log('Entities:', entities);
// Summarize text
const summary = await summarize(text, { maxLength: 50 });
console.log('Summary:', summary);
}
Configure the AI service.
Options:
apiKey
- API key for the AI serviceendpoint
- API endpoint (default: 'https://api.openai.com/v1')model
- Model to use (default: 'gpt-3.5-turbo')maxTokens
- Maximum tokens to generate (default: 1000)temperature
- Temperature for generation (default: 0.7)Generate text using the configured AI service.
Parameters:
prompt
- The prompt to generate fromoptions
- Additional options (same as configure)Returns: Promise resolving to the generated text
Create a composable AI hook for use in components.
Returns: An object with:
generate(prompt, options)
- Function to generate textloading()
- Function that returns the loading stateerror()
- Function that returns any errorresult()
- Function that returns the latest resultAnalyze the sentiment of text.
Returns: Promise resolving to "positive", "negative", or "neutral"
Extract named entities from text.
Returns: Promise resolving to an array of entity objects
Summarize text.
Options:
maxLength
- Maximum length of the summary in words (default: 100)Returns: Promise resolving to the summarized text
import { createAIManager } from '@kalxjs/ai';
const ai = createAIManager({
apiKeys: {
openai: 'your-api-key' // Or use environment variables
},
defaultOptions: {
model: 'gpt-3.5-turbo',
temperature: 0.7,
maxTokens: 1000
}
});
// Use the manager for various AI operations
async function processData(text) {
// Generate text
const generatedText = await ai.generateText({
prompt: 'Explain the following concept: ' + text
});
// Analyze sentiment
const sentiment = await ai.analyzeSentiment(text);
// Extract entities
const entities = await ai.extractEntities(text);
// Summarize
const summary = await ai.summarize(text, { maxLength: 50 });
return {
generatedText,
sentiment,
entities,
summary
};
}
For security reasons, it's recommended to store your API keys in environment variables:
import { configure, getEnvVar } from '@kalxjs/ai';
// Get API key from environment variable
const apiKey = getEnvVar('OPENAI_API_KEY');
// Configure the AI service
configure({
apiKey,
model: 'gpt-3.5-turbo'
});
The current implementation (v1.2.12) has some limitations:
For detailed version history and changes, please refer to the CHANGELOG.md file in the repository.
MIT
FAQs
AI integration utilities for KalxJS applications
We found that @kalxjs/ai 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.