loserai
v1.2.4
Published
A developer-friendly SDK to send prompts to multiple LLM providers and save responses to files.
Maintainers
Readme
loserai
The Elite AI Engineering SDK — A project-aware, streaming-first CLI and SDK that makes LLM integration unstoppable.
Advanced Features
- Smart Context (Project Awareness): Automatically scans your directory, reads your
README.md, and understands your file structure. - Semantic Code Graph (RAG): Deep-dives into your project to find the exact code snippets relevant to your prompt.
- Autonomous Self-Healing: Validates code via shell commands (e.g.,
npm test) and automatically fixes errors until it passes. - Multi-File Orchestration: Proposes and applies changes across multiple files in a single atomic operation.
- Multi-Provider Backbone: Supports
groq,nim,gemini,grok, andollamawith a resilient fallback chain. If one API limit is hit, it auto-fails over to the next. - Actionable Agentic Tools: Allow the AI to request system actions like installing dependencies or running shell commands.
- Live Streaming UI: Watch the AI "type" in real-time directly in your terminal with beautiful formatting.
- Unstoppable Fallback: Local-first mindset. Falls back to your local Ollama instance if cloud APIs fail.
- Resilient Fallback Chain: Automatically cycles through
Groq→NVIDIA NIM→Gemini→Grok→Ollama.
Installation
npm install loserai
# or use it instantly via npx
npx loserai "Explain quantum physics" physics.txtQuick Start
CLI (The "Instant" Way)
loserai is built to be used directly from your terminal.
# Watch it stream a project-aware summary
npx loserai "Summarize this project" summary.txt --context
# Write code with local Ollama fallback
npx loserai "Write a thread-safe Queue in C++" queue.cpp --fallback
# Use the Elite Features
npx loserai "Refactor my SDK" src/index.ts --semantic --multi --validate "npm test"
npx loserai "Setup a new project" init.txt --toolsSDK (The "Programmatic" Way)
import { generate } from "loserai";
const result = await generate({
prompt: "Build a responsive React navigation bar",
output: "src/components/Nav.tsx",
context: true, // Enable Project Awareness
stream: true, // Enable real-time console streaming
fallback: true, // Enable auto-resilience
onChunk: (chunk) => {
// Optional: Do something with each token as it arrives
}
});
console.log(`Success! Result saved to: ${result.outputPath}`);Core Capabilities
Smart Context (--context)
When enabled, loserai doesn't just look at your prompt. It scans your cwd (current working directory) to inject:
- Project Structure: A tree view of your files (up to depth 3).
- Project Identity: The contents of your
README.mdandpackage.json. - Style Matching: The AI learns your naming conventions and library choices.
Live Streaming
Streaming is enabled by default in the CLI. The SDK supports an onChunk callback for building your own streaming UIs.
- CLI: Instant feedback, no spinners, real-time typing.
- SDK:
AsyncIterablesupport for high-concurrency streaming.
Local Model Support (Ollama)
loserai is built for privacy and reliability. If you have Ollama running locally, it will act as a failsafe "Safety Net."
- No Internet? No problem.
- API Limits? It switches to local automatically.
- Privacy? Use
provider: "ollama"for 100% local processing.
Dynamic Token Scaling
loserai analyzes your prompt's intent:
- Simple (Math/Short questions): Limits response to ~150 tokens. Instructs AI to be "Extremely Concise."
- Complex (Coding/Architecture): Unlocks ~4096 tokens. Instructs AI to provide "Production-Ready Implementations."
Configuration
1. Configure your API keys:
Create a .env file in your project root, or set environment variables:
GROQ_API_KEY=your_groq_key
NIM_API_KEY=your_nim_key
GEMINI_API_KEY=your_gemini_key
GROK_API_KEY=your_grok_key
# OLLAMA_URL is optional (defaults to http://localhost:11434)
OLLAMA_URL=http://localhost:11434/api/chat
OLLAMA_MODEL=llama3Comparison
| Feature | loserai | Other SDKs | |---|---|---| | Autonomous Self-Healing | Yes (Auto-Retries on Error) | No | | Semantic Context (RAG) | Yes (Local Keyword Graph) | Manual | | Multi-File Output | Yes (Atomic Orchestration) | Single File Only | | Actionable Tools | Yes (Agentic Execution) | No | | Project Awareness | Yes (Smart Context) | No | | Live Streaming | Yes (Default) | Manual | | Local Fallback | Yes (Ollama Support) | No | | Resilience | Auto-Fallback Chain | Static | | Cost Saving | Smart Intent Scaling | Fixed Limits |
License
MIT © pritpatel2412 & Contributors
