npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dloizides/text-generation

v1.0.0

Published

Provider-agnostic text/copy generation seam — one TextGenerator interface over an in-browser WebLLM engine or a remote OpenAI-compatible API. The text seam of the generation abstraction.

Downloads

117

Readme

@dloizides/text-generation

Provider-agnostic text / copy generation — one TextGenerator interface over either an in-browser WebLLM engine (runs on WebGPU, no API keys, no server) or a remote OpenAI-compatible API. This is the text seam of the cross-product generation abstraction (Capability Wave C3): consumers depend on the interface, so the backend is swappable without code change.

Why

Both a loaded WebLLM engine and an OpenAI-style API speak the same chat.completions.create({ messages, max_tokens, temperature }) shape. So the only difference between "generate in the browser" and "generate via an API" is which create-function you inject — the generator code is identical.

Install

npm i @dloizides/text-generation

Zero runtime deps. For the in-browser path, the consumer provides @mlc-ai/web-llm (the heavy WebGPU engine) and injects the loaded engine — it is not a dependency of this package.

In-browser (WebLLM)

import {
  ChatCompletionsTextGenerator,
  generateJsonObject,
  isWebGpuSupported,
} from '@dloizides/text-generation';

if (!isWebGpuSupported()) { /* disable the Generate button */ }

const webllm = await import('@mlc-ai/web-llm');
const engine = await webllm.CreateMLCEngine('Llama-3.2-1B-Instruct-q4f16_1-MLC');

const generator = new ChatCompletionsTextGenerator((req) =>
  engine.chat.completions.create(req),
);

const draft = await generateJsonObject(generator, {
  system: 'You are a copywriter. Respond with JSON only.',
  prompt: 'Event: KUCY, Nicosia, 16 May 2026',
});

Remote API (OpenAI-compatible)

import {
  ChatCompletionsTextGenerator,
  createOpenAiChatCompletions,
} from '@dloizides/text-generation';

const create = createOpenAiChatCompletions({
  apiKey: process.env.OPENAI_API_KEY!,   // keep server-side
  model: 'gpt-4o-mini',
});
const generator = new ChatCompletionsTextGenerator(create);
const text = await generator.generate({ system, prompt });

API

  • TextGenerator — the seam: generate(request): Promise<string>.
  • ChatCompletionsTextGenerator — wraps any OpenAI-shape create function (a WebLLM engine or a remote client).
  • createOpenAiChatCompletions(opts) — fetch-based OpenAI-compatible provider (fetchImpl injectable for tests).
  • generateJsonObject(generator, request) / parseJsonObject(raw) / stripJsonFences(raw) — JSON-output helpers (tolerant of markdown fences).
  • isWebGpuSupported() — cheap synchronous WebGPU gate (safe off-browser).
  • TextGenerationError — thrown on unavailable backend / empty / unparseable output.
  • Defaults: maxTokens 600, temperature 0.7, OpenAI base URL https://api.openai.com/v1.