Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clean up bindings dir and move tests around #16

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
10 changes: 5 additions & 5 deletions docs/developers/01_getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
- [`packages/storage`](#packagesstorage)
- [`packages/ai`](#packagesai)
- [`packages/ai-provider`](#packagesai-provider)
- [`examples/cli`](#samplescli)
- [`examples/web`](#samplesweb)
- [`examples/ngraph`](#samplesngraph)
- [`examples/cli`](#examplescli)
- [`examples/web`](#examplesweb)
- [`examples/ngraph`](#examplesngraph)

# Developer Getting Started

Expand All @@ -51,7 +51,7 @@ After this, plese read [Architecture](02_architecture.md) before attempting to [

```ts
import { TaskGraphBuilder } from "ellmers-core";
import { registerHuggingfaceLocalTasksInMemory } from "ellmers-ai-provider/hf-transformers/server";
import { registerHuggingfaceLocalTasksInMemory } from "ellmers-test";
// config and start up
registerHuggingfaceLocalTasksInMemory();

Expand Down Expand Up @@ -79,8 +79,8 @@ import {
DataFlow,
TaskGraph,
TaskGraphRunner,
registerHuggingfaceLocalTasksInMemory,
} from "ellmers-core";
import { registerHuggingfaceLocalTasksInMemory } from "ellmers-test";

// config and start up
registerHuggingfaceLocalTasksInMemory();
Expand Down
7 changes: 5 additions & 2 deletions examples/cli/src/ellmers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { program } from "commander";
import { argv } from "process";
import { AddBaseCommands } from "./TaskCLI";
import { getProviderRegistry } from "ellmers-ai";
import { registerHuggingfaceLocalTasksInMemory } from "ellmers-ai-provider/hf-transformers/server";
import { registerMediaPipeTfJsLocalInMemory } from "ellmers-ai-provider/tf-mediapipe/server";
import {
registerHuggingfaceLocalTasksInMemory,
registerMediaPipeTfJsLocalInMemory,
} from "ellmers-test";
import "ellmers-test";

program.version("1.0.0").description("A CLI to run Ellmers.");

Expand Down
34 changes: 31 additions & 3 deletions examples/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,47 @@ import React, { useCallback, useEffect, useState } from "react";
import { ReactFlowProvider } from "@xyflow/react";
import { RunGraphFlow } from "./RunGraphFlow";
import { JsonEditor } from "./JsonEditor";
import { JsonTask, JsonTaskItem, TaskGraph, TaskGraphBuilder } from "ellmers-core";
import {
ConcurrencyLimiter,
JsonTask,
JsonTaskItem,
TaskGraph,
TaskGraphBuilder,
TaskInput,
TaskOutput,
} from "ellmers-core";
import {
IndexedDbQueue,
IndexedDbTaskGraphRepository,
IndexedDbTaskOutputRepository,
} from "ellmers-storage/browser/indexeddb";
import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "./Resize";
import { QueuesStatus } from "./QueueSatus";
import { OutputRepositoryStatus } from "./OutputRepositoryStatus";
import { GraphStoreStatus } from "./GraphStoreStatus";
import { registerHuggingfaceLocalTasksInMemory } from "ellmers-ai-provider/hf-transformers/browser";
import { InMemoryJobQueue } from "ellmers-storage/inmemory";
import { registerHuggingfaceLocalTasks } from "ellmers-ai-provider/hf-transformers/browser";
import { getProviderRegistry, ModelProcessorEnum } from "ellmers-ai";
import { registerMediaPipeTfJsLocalTasks } from "ellmers-ai-provider/tf-mediapipe/browser";
import "ellmers-task";
import "ellmers-test";

const ProviderRegistry = getProviderRegistry();

registerHuggingfaceLocalTasks();
ProviderRegistry.registerQueue(
ModelProcessorEnum.LOCAL_ONNX_TRANSFORMERJS,
new InMemoryJobQueue<TaskInput, TaskOutput>("local_hft", new ConcurrencyLimiter(1, 10), 10)
);

registerMediaPipeTfJsLocalTasks();
ProviderRegistry.registerQueue(
ModelProcessorEnum.MEDIA_PIPE_TFJS_MODEL,
new InMemoryJobQueue<TaskInput, TaskOutput>("local_mp", new ConcurrencyLimiter(1, 10), 10)
);

registerHuggingfaceLocalTasksInMemory();
ProviderRegistry.clearQueues();
ProviderRegistry.startQueues();

const taskOutputCache = new IndexedDbTaskOutputRepository();
const builder = new TaskGraphBuilder(taskOutputCache);
Expand Down
5 changes: 0 additions & 5 deletions examples/web/src/RunGraphFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ import { TurboNodeData, SingleNode, CompoundNode } from "./TurboNode";
import TurboEdge from "./TurboEdge";
import { FiFileText, FiClipboard, FiDownload, FiUpload } from "react-icons/fi";
import { Task, TaskGraph } from "ellmers-core";
import { registerHuggingfaceLocalTasksInMemory } from "ellmers-ai-provider/hf-transformers/browser";
import { registerMediaPipeTfJsLocalInMemory } from "ellmers-ai-provider/tf-mediapipe/browser";
import { GraphPipelineCenteredLayout, GraphPipelineLayout, computeLayout } from "./layout";

import "@xyflow/react/dist/base.css";
import "./RunGraphFlow.css";

registerHuggingfaceLocalTasksInMemory();
registerMediaPipeTfJsLocalInMemory();

const categoryIcons = {
"Text Model": <FiFileText />,
Input: <FiUpload />,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
"build:ai-provider": "cd packages/ai-provider && bun run build",
"build:storage": "cd packages/storage && bun run build",
"build:task": "cd packages/task && bun run build",
"build:test": "cd packages/test && bun run build",
"build:examples": "bun run bun run build:cli && bun run build:web",
"build:cli": "cd examples/cli && bun run build",
"build:web": "cd examples/web && bun run build",
"clean": "rm -rf node_modules packages/*/node_modules packages/*/dist packages/*/src/**/*\\.d\\.ts packages/*/src/**/*\\.map examples/*/node_modules examples/*/dist examples/*/src/**/*\\.d\\.ts examples/*/src/**/*\\.map",
"watch:packages": "concurrently --kill-others -c 'auto' -n core,task,storage,ai,provider 'cd packages/core && bun run watch' 'sleep 3 && cd packages/task && bun run watch' 'sleep 3 && cd packages/storage && bun run watch' 'sleep 3 && cd packages/ai && bun run watch' 'sleep 6 && cd packages/ai-provider && bun run watch'",
"watch:packages": "concurrently --kill-others -c 'auto' -n core,task,storage,ai,provider,test 'cd packages/core && bun run watch' 'sleep 3 && cd packages/task && bun run watch' 'sleep 3 && cd packages/storage && bun run watch' 'sleep 3 && cd packages/ai && bun run watch' 'sleep 6 && cd packages/ai-provider && bun run watch' 'sleep 10 && cd packages/test && bun run watch'",
"docs": "typedoc",
"format": "eslint \"{packages|examples}/*/src/**/*.{js,ts,tsx,json}\" --fix && prettier \"{packages|examples}/*/src/**/*.{js,ts,tsx,json}\" --check --write",
"release": "bun run build && bun publish",
Expand Down
17 changes: 0 additions & 17 deletions packages/ai-provider/src/hf-transformers/bindings/all_inmemory.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/ai-provider/src/hf-transformers/bindings/all_sqlite.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/ai-provider/src/hf-transformers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

export * from "./provider/HuggingFaceLocal_TaskRun";
export * from "./model/ONNXTransformerJsModel";
export * from "./bindings/local_hf";
export * from "./bindings/all_inmemory";
export * from "./bindings/registerTasks";
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// *******************************************************************************
// * ELLMERS: Embedding Large Language Model Experiential Retrieval Service *
// * *
// * Copyright Steven Roussey <[email protected]> *
// * Licensed under the Apache License, Version 2.0 (the "License"); *
// *******************************************************************************

import { describe, expect, it } from "bun:test";
import { ConcurrencyLimiter, TaskGraphBuilder, TaskInput, TaskOutput } from "ellmers-core";
import { getProviderRegistry, ModelProcessorEnum, ModelUseCaseEnum } from "ellmers-ai";
import { InMemoryJobQueue } from "ellmers-storage/inmemory";
import { SqliteJobQueue } from "ellmers-storage/bun/sqlite";
import { registerHuggingfaceLocalTasks } from "../bindings/registerTasks";
import { getDatabase } from "../../../../storage/src/util/db_sqlite";
import { sleep } from "bun";
import { ONNXTransformerJsModel } from "../model/ONNXTransformerJsModel";

const HFQUEUE = "local_hf";

describe("HFTransformersBinding", () => {
describe("InMemoryJobQueue", () => {
it("Should have an item queued", async () => {
// the model gets self-registered
const flanT5p786m = new ONNXTransformerJsModel(
"Xenova/LaMini-Flan-T5-783M",
[ModelUseCaseEnum.TEXT_GENERATION, ModelUseCaseEnum.TEXT_REWRITING],
"text2text-generation"
);
registerHuggingfaceLocalTasks();
const providerRegistry = getProviderRegistry();
const jobQueue = new InMemoryJobQueue<TaskInput, TaskOutput>(
HFQUEUE,
new ConcurrencyLimiter(1, 10),
10
);
providerRegistry.registerQueue(ModelProcessorEnum.LOCAL_ONNX_TRANSFORMERJS, jobQueue);
const queue = providerRegistry.getQueue(ModelProcessorEnum.LOCAL_ONNX_TRANSFORMERJS);
expect(queue).toBeDefined();
expect(queue?.queue).toEqual(HFQUEUE);

const builder = new TaskGraphBuilder();
builder.DownloadModel({
model: "Xenova/LaMini-Flan-T5-783M",
});
builder.run();
await sleep(1);
expect(await queue?.size()).toEqual(1);
await queue?.clear();
});
});

describe("SqliteJobQueue", () => {
it("Should have an item queued", async () => {
registerHuggingfaceLocalTasks();
const providerRegistry = getProviderRegistry();
const jobQueue = new SqliteJobQueue<TaskInput, TaskOutput>(
getDatabase(),
HFQUEUE,
new ConcurrencyLimiter(1, 10),
10
);
jobQueue.ensureTableExists();
providerRegistry.registerQueue(ModelProcessorEnum.LOCAL_ONNX_TRANSFORMERJS, jobQueue);
const queue = providerRegistry.getQueue(ModelProcessorEnum.LOCAL_ONNX_TRANSFORMERJS);
expect(queue).toBeDefined();
expect(queue?.queue).toEqual(HFQUEUE);

const builder = new TaskGraphBuilder();
builder.DownloadModel({
model: "Xenova/LaMini-Flan-T5-783M",
});
builder.run();
await sleep(1);
expect(await queue?.size()).toEqual(1);
builder.reset();
await queue?.clear();
});
});
});
19 changes: 0 additions & 19 deletions packages/ai-provider/src/tf-mediapipe/bindings/all_inmemory.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/ai-provider/src/tf-mediapipe/bindings/all_sqlite.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/ai-provider/src/tf-mediapipe/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

export * from "./provider/MediaPipeLocalTaskRun";
export * from "./model/MediaPipeModel";
export * from "./bindings/local_mp";
export * from "./bindings/all_inmemory";
export * from "./bindings/registerTasks";
Loading
Loading