formstr-llm-service
v0.1.1
Published
Unified LLM service (Ollama + WebLLM) for Formstr apps
Readme
@formstr/llm-service
Unified LLM service for Formstr — supports Ollama (local extension) and WebLLM (in-browser inference).
Install
npm install @formstr/llm-service
# WebLLM support also needs:
npm install @mlc-ai/web-llmUsage
import { llmService, LLMProvider } from "@formstr/llm-service";
// Switch provider
llmService.setProvider(LLMProvider.OLLAMA); // or WEB_LLM
// Configure
llmService.setConfig({ modelName: "llama3.2", baseUrl: "http://localhost:11434" });
// Test connection
const { success } = await llmService.testConnection();
// List available models
const { models } = await llmService.fetchModels();
// Generate
const result = await llmService.generate({
prompt: 'USER REQUEST: "contact form"\nYOUR JSON RESPONSE:',
system: "Return only valid JSON.",
format: "json",
modelName: "llama3.2",
});WebLLM — download a model
import { llmService, LLMProvider, WebLLMService } from "@formstr/llm-service";
llmService.setProvider(LLMProvider.WEB_LLM);
const webService = llmService.activeService as WebLLMService;
await webService.downloadModel("Llama-3.2-1B-Instruct-q4f32_1-MLC", (progressText) => {
console.log(progressText); // "Loading model: 45%"
});