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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ai-mask/sdk

v0.9.0

Published

**Bring local inference into your app !**

Downloads

21

Readme

AI-Mask SDK

Bring local inference into your app !

Download extension | Demo App | Home Page | Quick Start

npm version

This is an alpha version

Easily support AI-Mask in your AI apps, and bring free and private local-inference to your users ! Do not store API keys again, and get rid of your backend and server costs.

Note: App users must have the extension installed for this SDK to work on web pages

Quick Start

Install package:

npm install -S @ai-mask/sdk

Run inference:

import { AIMaskClient } from '@ai-mask'

const messages = [{ role: 'user', content: 'What is the capital of France ? ' }]

const aiMaskClient = new AIMaskClient()
const response = await aiMaskClient.chat(
	{ messages },
  { modelId: 'gemma-2b-it-q4f32_1' },
)

Integration examples

API

AIMaskClient

import { AIMaskClient } from '@ai-mask/sdk'

// Check if extension is installed
AIMaskClient.isExtensionAvailable(): boolean

// Instanciate
const aiMaskClient = new AIMaskClient({ name?: string }) // name of your app

// List available models
async aiMaskClient.getModels(): Promise<Model[]>

type Model {
    id: string
    name: string
    task: string
}

// Chat with an OpenAI-like request
async aiMaskClient.chat(params: ChatCompletionParams, options: InferOptions): Promise<string | ReadableStream<string>>

type ChatCompletionParams = {
    messages: [{ role: 'user' | 'assistant', content: string }]
    max_tokens: number
    temperature: number
}
type InferOptions = {
    modelId: string
    stream?: boolean
}

// Translate text from one language to another
async aiMaskClient.translate(params: TranslationParams, options: InferOptions): Promise<string>

type TranslationParams = {
    inputText: string
    sourceLang: string
    destLang: string
}

// Create embeddings
async aiMaskClient.featureExtraction(params: FeatureExtractionParams, options: InferOptions): Promise<number[][]>

type TranslationParams = {
    texts: string[]
    pooling?: 'none' | 'mean' | 'cls'
    normalize?: boolean
}

For sourceLang and destLang, see languages

Usage in Workers

If you need to use AIMask from a Web Worker, some additional steps are required.

Please check the demo app with worker for an example implementation.

  • In the worker, use async AIMaskClient.getWorkerClient() to get an AIMaskClient instance.
  • In the main thread, just after initializing your worker and having an AIMaskClient instance, call aiMaskClient.providerWorkerPort(worker)
// main.ts
const aiMaskClient = new AIMaskClient()
const worker = new Worker(
    new URL('./worker.ts', import.meta.url), 
    {
        type: 'module',
    });
aiMaskClient.provideWorkerPort(worker)
// worker.ts
const aiMaskClient = await AIMaskClient.getWorkerClient()