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

@dfinity/llm

v1.1.1

Published

TypeScript library for interacting with DFINITY's LLM canister on the Internet Computer

Readme

@dfinity/llm

A TypeScript library for making requests to the LLM canister on the Internet Computer.

Supported Models

The following LLM models are available:

  • Model.Llama3_1_8B - Llama 3.1 8B model
  • Model.Qwen3_32B - Qwen 3 32B model
  • Model.Llama4Scout - Llama 4 Scout model

Local Development Setup

Note: When developing locally, the architecture differs slightly from mainnet. Instead of using AI workers, the LLM canister connects directly to your local Ollama instance. This makes local development faster and easier, while still maintaining the same interface and behavior as the mainnet deployment. For more information about how the LLM canister works, see the How Does it Work?.

Before using this library in local development, you need to set up the LLM canister dependency:

Prerequisites

  • DFX installed
  • Ollama installed and running locally

Setup Steps

  1. Start Ollama (required for local development):
# Start the Ollama server
ollama serve

# Download the required model (one-time setup)
ollama run llama3.1:8b
  1. Add LLM canister to your dfx.json (Note: This only works for dfx <=0.25.0):
{
  "canisters": {
    "llm": {
      "type": "pull",
      "id": "w36hm-eqaaa-aaaal-qr76a-cai"
    },
    "your-canister": {
      "dependencies": ["llm"],
      "type": "azle"
    }
  }
}

Alternatively you can also define the llm dependency like this:

    "llm": {
      "candid": "https://github.com/dfinity/llm/releases/latest/download/llm-canister-ollama.did",
      "type": "custom",
      "specified_id": "w36hm-eqaaa-aaaal-qr76a-cai",
      "remote": {
        "id": {
          "ic": "w36hm-eqaaa-aaaal-qr76a-cai"
        }
      },
  1. Deploy locally:
dfx start --clean
dfx deps pull
dfx deps deploy
dfx deploy

Install

npm install @dfinity/llm

Usage

Prompting (single message)

import { IDL, update } from "azle";
import * as llm from "@dfinity/llm";

export default class {
  @update([IDL.Text], IDL.Text)
  async prompt(prompt: string): Promise<string> {
    return await llm.prompt(llm.Model.Llama3_1_8B, prompt);
  }
}

Chatting (multiple messages)

import { IDL, update } from "azle";
import * as llm from "@dfinity/llm";

export default class {
  @update([IDL.Vec(llm.ChatMessage)], IDL.Text)
  async chat(messages: llm.ChatMessage[]): Promise<string> {
    const response = await llm.chat(llm.Model.Llama3_1_8B)
      .withMessages(messages)
      .send();
    
    return response.message.content[0] || "";
  }
}

Tool Calls

import { IDL, update } from "azle";
import * as llm from "@dfinity/llm";

export default class {
  @update([IDL.Text], llm.ChatResponse)
  async chatWithTools(userMessage: string): Promise<llm.ChatResponse> {
    const messages: llm.ChatMessage[] = [
      {
        user: {
          content: userMessage
        }
      }
    ];

    // Define a tool that allows the LLM to get weather information for a location
    const tools: llm.Tool[] = [
      {
        name: "get_weather",
        description: "Get the current weather for a location",
        parameters: [
          {
            name: "location",
            type: "string",
            description: "The city and state, e.g. San Francisco, CA",
            required: true
          }
        ]
      }
    ];

    return await llm.chat(llm.Model.Llama3_1_8B)
      .withMessages(messages)
      .withTools(tools)
      .send();
  }
}