effidevFlutter · Edge de Cloudflare · Optimización de costes en la nube
Español

Ejecutando LLMs On-Device (Gemma/Phi-3) en Flutter con MediaPipe LLM Inference API

Flutter On-Device LLM MediaPipe Gemma Phi-3 Integration

El IA On-Device permite ejecutar modelos de lenguaje (LLM) directamente en el dispositivo móvil sin depender de API en la nube.

Con la API MediaPipe LLM Inference de Google, es posible ejecutar Gemma 2B y Phi-3 Mini en Flutter de forma 100% offline y sin costes de servidor.

Puntos clave

  • Ventajas: Coste $0 en servidores, privacidad total y respuesta instantánea.
  • Cuantización a 4 bits (int4): Reduce el uso de memoria a menos de 1.5GB de RAM.
  • Stream en Flutter: Integración fluida mediante MethodChannel y StreamBuilder.

1. Integración en Flutter

class OnDeviceLlmService {
  static const MethodChannel _channel = MethodChannel('dev.effidev.mediapipe_llm');

  Future<void> initializeModel(String modelPath) async {
    await _channel.invokeMethod('initModel', {'modelPath': modelPath});
  }
}