xybrid library
Xybrid - Hybrid cloud-edge ML inference orchestrator.
This library provides a clean Dart API for running ML models on-device or in the cloud, with intelligent routing based on device capabilities.
Initialization
You must call Xybrid.init once before using any Xybrid functionality:
void main() async {
await Xybrid.init();
runApp(MyApp());
}
Quick Start
// Initialize once at app startup
await Xybrid.init();
// Load a model from registry
final loader = XybridModelLoader.fromRegistry('kokoro-82m');
final model = await loader.load();
// Run text-to-speech
final envelope = XybridEnvelope.text('Hello, world!');
final result = await model.run(envelope);
final audioBytes = result.audioBytes;
Pipelines
// Load and run a pipeline
final pipeline = XybridPipeline.fromYaml('''
name: speech-to-text
stages:
- model: whisper-small
''');
final envelope = XybridEnvelope.audio(bytes: audioData, sampleRate: 16000);
final result = await pipeline.run(envelope);
Conversation Context (LLM)
// Create conversation context for multi-turn chat
final context = ConversationContext();
context.setSystem('You are a helpful assistant.');
// Run with context
context.pushText('Hello!', MessageRole.user);
final result = await model.runWithContext(
XybridEnvelope.text('Hello!'),
context,
);
context.pushText(result.text ?? '', MessageRole.assistant);
Classes
- XybridModelLoader - Prepare and load models from registry or bundles
- XybridModel - A loaded model ready for inference
- XybridEnvelope - Input data wrapper for different modalities
- XybridResult - Inference output containing text, audio, or embeddings
- XybridPipeline - Multi-stage inference pipeline
- ConversationContext - Multi-turn conversation memory for LLMs
- MessageRole - Message role for conversation turns
- GenerationConfig - LLM generation parameters (temperature, top-p, etc.)
Classes
- ConversationContext
- Manages multi-turn conversation history for LLM models.
- GenerationConfig
- Generation parameters for LLM inference.
- LoadComplete
- Model loading completed successfully.
- LoadError
- Model loading failed with an error.
- LoadEvent
- Event emitted during model loading with progress tracking.
- LoadProgress
- Download progress update (0.0 to 1.0).
- StreamToken
- A single token emitted during streaming generation.
- Xybrid
- Main entry point for the Xybrid SDK.
- XybridEnvelope
- Envelope containing input data for model inference.
- XybridModel
- A loaded model ready for inference.
- XybridModelLoader
- Prepares a model for loading from registry or local bundle.
- XybridPipeline
- A loaded pipeline ready for multi-stage inference.
- XybridResult
- Result of a model inference operation.
Enums
- MessageRole
- Message role for conversation turns.
Functions
-
wrapInWavHeader(
Uint8List pcmBytes, {required int sampleRate, required int channels}) → Uint8List - Wraps raw PCM audio bytes in a WAV header for playback.
Exceptions / Errors
- XybridException
- Exception thrown when Xybrid operations fail.