ai_assistant_core
Simple, ergonomic Rust client and server for local LLMs.
Connect to Ollama, LM Studio, or any OpenAI-compatible server in a few lines of code. Or serve your local model as an OpenAI-compatible API accessible remotely.
Quick Start
[]
= "0.2"
= { = "1", = ["rt-multi-thread", "macros"] }
use ollama;
async
Features
- Auto-detection: Scans localhost for running providers automatically
- Multi-provider: Ollama, LM Studio, any OpenAI-compatible API
- Streaming: Token-by-token responses via
futures::Stream - Message history: Full conversation support with system/user/assistant roles
- Serve mode: Expose your local LLM as an OpenAI-compatible HTTP API
- NAT traversal: STUN discovery + UPnP/NAT-PMP port mapping for remote access
- Standalone binary:
ai_serve— one command to share your model - Minimal dependencies: Lightweight, fast to compile
- MIT / Apache-2.0: Use it anywhere
Providers
use ;
let o = ollama; // localhost:11434
let o2 = ollama_at; // remote Ollama
let lm = lm_studio; // localhost:1234
let c = openai_compat; // any compatible API
Streaming
use ollama;
use StreamExt;
# async
Conversation History
use ;
# async
Auto-Detection
Don't know what's running? Let detect() find providers for you:
use detect;
# async
Checks OLLAMA_HOST / LM_STUDIO_URL env vars, falls back to default ports.
Pass extra URLs for custom endpoints: detect(&["http://gpu-server:11434"]).
Serve Your Model
Expose your local LLM as an OpenAI-compatible API that anyone can connect to:
[]
= { = "0.2", = ["serve"] }
use ;
async
With builder for more control:
use ;
# async
Endpoints provided:
GET /health— health checkGET /v1/models— list available modelsPOST /v1/chat/completions— chat (streaming supported)
Remote Access (NAT Traversal)
Enable the nat feature to discover your public IP via STUN and automatically open ports via UPnP or NAT-PMP:
[]
= { = "0.2", = ["serve", "nat"] }
When you call .nat() on the builder, it will:
- Query STUN servers to discover your public IP
- Attempt UPnP IGD port mapping on your router
- Fall back to NAT-PMP if UPnP fails
- Report the public URL in
ServiceInfo
No need for ngrok, cloudflare tunnel, or VPN.
Standalone Binary
Compile and run ai_serve for a zero-code way to share your model:
# Auto-detect backend and serve
# With NAT traversal and authentication
# Explicit backend
Any OpenAI-compatible client can then connect:
Need More?
For advanced features like RAG, multi-agent orchestration, security guardrails, distributed clusters, MCP protocol, autonomous agents, and more, check out the full ai_assistant suite.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.