This guide covers only the simplest steps to run an LLM on your device. For a detailed, step-by-step explanation of how everything works, see the full integration guide.
1

Make a new project folder

mkdir demo && cd demo
2

Initialize with pnpm

pnpm init
3

Install dependencies

pnpm add typescript ts-node @types/node -D
pnpm add @trymirai/uzu
4

Initialize a tsconfig.json

{
    "compilerOptions": {
        "target": "es2020",
        "module": "commonjs",
        "moduleResolution": "node",
        "strict": true,
        "esModuleInterop": true,
        "outDir": "dist",
        "types": [
            "node"
        ]
    },
    "include": [
        "*.ts"
    ]
}
5

Get an API key

Go to Platform and follow this guide.
6

Create main.ts

Don’t forget to add your API key.
import {
    Engine,
    Phase,
    SessionMessageRole,
    type LicenseStatus,
    type LocalModel,
    type ModelDownloadState,
    type ModelID,
    type Session,
    type SessionConfig,
    type SessionInput,
    type SessionRunConfig,
} from '@trymirai/uzu'

async function main() {
    //activate
    const engine = new Engine()
    const licenseStatus: LicenseStatus = await engine.activate("API_KEY")
    if (
        licenseStatus.type !== 'Activated' &&
        licenseStatus.type !== 'GracePeriodActive'
    ) {
        return
    }

    //update models list
    const localModels: LocalModel[] = await engine.updateRegistry()
    const localModelId = 'Meta-Llama-3.2-1B-Instruct-bfloat16'

    //download model
    const modelState: ModelDownloadState = engine.getState(localModelId)
    if (modelState.phase !== Phase.Downloaded) {
        const donwloadHandle = engine.downloadHandle(localModelId)
        donwloadHandle.start()
        for await (const donwloadProgress of donwloadHandle.progress()) {
            console.log("Progress:", donwloadProgress.progress)
        }
    }

    //create and load inference session
    const modelId: ModelID = { type: 'Local', id: localModelId }
    const session: Session = engine.createSession(modelId)
    const config: SessionConfig = {
        preset: { type: 'General' },
        samplingSeed: { type: 'Default'  },
        contextLength: { type: 'Default' },
    }
    session.load(config)
    
    //create input
    const input: SessionInput = {
        type: 'Messages',
        messages: [
            {
                role: SessionMessageRole.System,
                content: 'You are a helpful assistant.'
            },
            {
                role: SessionMessageRole.User,
                content: 'Tell me a short, funny story about a robot.'
            },
        ],
    }

    //run
    const runConfig: SessionRunConfig = {
        tokensLimit: 256
    }
    try {
        const output = session.run(input, runConfig, (partialOutput) => {
            return true
        })
        console.log('Output:', output)
    } catch (err) {
        console.error('Error:', err)
    }
}

main().catch((err) => {
    console.error('An unexpected error occurred:', err)
})
7

Run the snippet

pnpm ts-node main.ts
Now that we’ve tried the simplest snippet, let’s take a look at the step-by-step integration guide.