napi-deviceinfo-ai
v1.0.1
Published
AI-powered device information package - ask questions about your machine in natural language
Maintainers
Readme
NAPI Device Info AI
🤖 Ask questions about your machine in natural language!
An AI-powered Node.js package that lets you query your Windows device information using natural language. Powered by Azure OpenAI and native Windows APIs through N-API.
Features
- 💬 Natural Language Interface: Ask questions like "What's my computer name?" or "How busy is my machine?"
- 🚀 Native Performance: Uses N-API for fast, direct access to Windows system information
- 🤖 AI-Powered: Integrates with Azure OpenAI to understand and respond to your queries
- 🔧 Easy to Use: Simple API with sensible defaults
- 📊 System Information: Get device name, process count, and memory information
- 🗂️ Multi-Drive Support: Comprehensive storage information across all drives
- 📝 Full TypeScript Support: Complete type definitions included
Installation
npm install napi-deviceinfo-aiNote: This package is Windows-only and requires Node.js 16+.
Prerequisites
You'll need an Azure OpenAI API key to use this package. Get one from the Azure OpenAI Service.
Quick Start
import { askAboutDevice } from 'napi-deviceinfo-ai';
// Ask a question about your device
const response = await askAboutDevice("What is my computer name?", {
apiKey: "your-azure-openai-api-key"
});
console.log(response);
// Output: "Your computer name is DESKTOP-ABC123."API Reference
askAboutDevice(query, options)
Main function to ask questions about your device using AI.
Parameters:
query(string): Your question in natural languageoptions(object): Configuration optionsapiKey(string, required): Your Azure OpenAI API keyendpoint(string, optional): Azure OpenAI endpoint (default: uses built-in endpoint)modelName(string, optional): Model to use (default: "gpt-4")deployment(string, optional): Deployment name (default: "gpt-4")apiVersion(string, optional): API version (default: "2024-04-01-preview")verbose(boolean, optional): Enable detailed logging (default: false)
Returns: Promise - AI response about your device
Native Functions
You can also access the underlying system information directly:
import { getDeviceName, getProcessCount, getTotalPhysicalMemory } from 'napi-deviceinfo-ai';
const deviceName = getDeviceName(); // "DESKTOP-ABC123"
const processCount = getProcessCount(); // 156
const totalMemory = getTotalPhysicalMemory(); // 17179869184 (bytes)Example Queries
The AI can understand various types of questions:
const examples = [
"What is my machine name?",
"How many processes are running?",
"How much RAM does my computer have?",
"Give me a summary of my device",
"Is my computer busy right now?",
"What's the total memory in GB?",
"Show me my device information"
];
for (const query of examples) {
const response = await askAboutDevice(query, { apiKey: "your-key" });
console.log(`Q: ${query}`);
console.log(`A: ${response}\n`);
}TypeScript Support
Full TypeScript definitions are included with proper typing for all functions:
import {
askAboutDevice,
getCompleteDeviceInfo,
type CompleteDeviceInfo,
type DeviceInfoOptions
} from 'napi-deviceinfo-ai';
// Get complete device info with full typing
const deviceInfo: CompleteDeviceInfo = getCompleteDeviceInfo();
console.log('Device:', deviceInfo.deviceName);
console.log('Memory GB:', deviceInfo.totalMemoryBytes / (1024**3));
console.log('Drives:', deviceInfo.availableDrives);
// AI query with typed options
const options: DeviceInfoOptions = {
apiKey: "your-api-key",
verbose: true
};
const response = await askAboutDevice("What's my computer?", options);Environment Variables
You can set your API key as an environment variable:
# Windows Command Prompt
set AZURE_OPENAI_API_KEY=your-api-key-here
# PowerShell
$env:AZURE_OPENAI_API_KEY="your-api-key-here"
# Then in your code:
const response = await askAboutDevice("What's my computer name?", {
apiKey: process.env.AZURE_OPENAI_API_KEY
});Error Handling
try {
const response = await askAboutDevice("What's my device name?", {
apiKey: "your-api-key"
});
console.log(response);
} catch (error) {
if (error.message.includes("API key")) {
console.error("Please provide a valid API key");
} else {
console.error("Error:", error.message);
}
}Building from Source
If you want to build the native components:
# Install dependencies
npm install
# Build the native addon
npm run build
# Run demo
npm run demoSystem Requirements
- OS: Windows only (win32)
- Node.js: 16.0.0 or higher
- Azure OpenAI: API key required
Contributing
Contributions welcome! This package uses:
- N-API for native Windows system calls
- Azure OpenAI for natural language processing
- node-gyp for building native addons
License
MIT
Ask your computer anything! 🚀
