Skip to content

Commit

Permalink
refactor: move inmemory from core to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
sroussey committed Jan 13, 2025
1 parent 46a41c4 commit e133784
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InMemoryJobQueue, ConcurrencyLimiter, TaskInput, TaskOutput } from "ellmers-core";
import { ConcurrencyLimiter, TaskInput, TaskOutput } from "ellmers-core";
import { getProviderRegistry, ModelProcessorEnum } from "ellmers-ai";

import { InMemoryJobQueue } from "ellmers-storage/inmemory";
import { registerHuggingfaceLocalTasks } from "./local_hf";
import "../model/ONNXModelSamples";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getProviderRegistry } from "ellmers-ai";
import { InMemoryJobQueue } from "ellmers-core";
import { InMemoryJobQueue } from "ellmers-storage/inmemory";
import { ModelProcessorEnum } from "ellmers-ai";
import { ConcurrencyLimiter } from "ellmers-core";
import { TaskInput, TaskOutput } from "ellmers-core";
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ export * from "./source/DocumentConverterMarkdown";
export * from "./task/index";
export * from "./storage/base/KVRepository";
export * from "./storage/taskoutput/TaskOutputRepository";
export * from "./storage/taskoutput/InMemoryTaskOutputRepository";
export * from "./storage/taskgraph/TaskGraphRepository";
export * from "./storage/taskgraph/InMemoryTaskGraphRepository";
export * from "./util/Misc";
export * from "./job/base/Job";
export * from "./job/base/JobQueue";
export * from "./job/InMemoryJobQueue";
export * from "./job/base/ILimiter";
export * from "./job/DelayLimiter";
export * from "./job/CompositeLimiter";
export * from "./job/ConcurrencyLimiter";
export * from "./job/InMemoryRateLimiter";
4 changes: 4 additions & 0 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"test": "bun test"
},
"exports": {
"./inmemory": {
"import": "./dist/browser/inmemory/index.js",
"types": "./dist/browser/inmemory/index.d.ts"
},
"./browser/indexeddb": {
"import": "./dist/browser/indexeddb/index.js",
"types": "./dist/browser/indexeddb/index.d.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
// * Licensed under the Apache License, Version 2.0 (the "License"); *
// *******************************************************************************

import { makeFingerprint } from "../util/Misc";
import { Job, JobStatus } from "./base/Job";
import { JobQueue } from "./base/JobQueue";
import { ILimiter } from "./base/ILimiter";
import { nanoid } from "nanoid";
import { Job, JobStatus, JobQueue, ILimiter } from "ellmers-core";
import { makeFingerprint } from "../../util/Misc";

export class InMemoryJobQueue<Input, Output> extends JobQueue<Input, Output> {
constructor(queue: string, limiter: ILimiter, waitDurationInMilliseconds = 100) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// * Licensed under the Apache License, Version 2.0 (the "License"); *
// *******************************************************************************

import { DiscriminatorSchema, KVRepository } from "./KVRepository";
import { DiscriminatorSchema, KVRepository } from "ellmers-core";
import { makeFingerprint } from "../../util/Misc";

// InMemoryKVRepository is a simple in-memory key-value store that can be used for testing or as a cache
Expand All @@ -14,7 +14,7 @@ import { makeFingerprint } from "../../util/Misc";
export class InMemoryKVRepository<
Key = string,
Value = string,
Discriminator extends DiscriminatorSchema = DiscriminatorSchema,
Discriminator extends DiscriminatorSchema = DiscriminatorSchema
> extends KVRepository<Key, Value, Discriminator> {
values = new Map<string, Value>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// * Licensed under the Apache License, Version 2.0 (the "License"); *
// *******************************************************************************

import { ILimiter } from "./base/ILimiter";
import { ILimiter } from "ellmers-core";

export class InMemoryRateLimiter implements ILimiter {
private requests: Date[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
// * Licensed under the Apache License, Version 2.0 (the "License"); *
// *******************************************************************************

import { TaskGraphJson } from "../../task/base/TaskGraph";
import { TaskGraphRepository } from "./TaskGraphRepository";
import { InMemoryKVRepository } from "../base/InMemoryKVRepository";
import { TaskGraphJson, TaskGraphRepository } from "ellmers-core";
import { InMemoryKVRepository } from "./InMemoryKVRepository";

export class InMemoryTaskGraphRepository extends TaskGraphRepository {
kvRepository: InMemoryKVRepository<unknown, TaskGraphJson>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
// * Licensed under the Apache License, Version 2.0 (the "License"); *
// *******************************************************************************

import { TaskInput, TaskOutput } from "../../task/base/Task";
import { TaskOutputDiscriminator, TaskOutputRepository } from "./TaskOutputRepository";
import { InMemoryKVRepository } from "../base/InMemoryKVRepository";
import { TaskInput, TaskOutput, TaskOutputDiscriminator, TaskOutputRepository } from "ellmers-core";
import { InMemoryKVRepository } from "./InMemoryKVRepository";

export class InMemoryTaskOutputRepository extends TaskOutputRepository {
kvRepository: InMemoryKVRepository<TaskInput, TaskOutput, typeof TaskOutputDiscriminator>;
Expand Down
5 changes: 5 additions & 0 deletions packages/storage/src/browser/inmemory/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./InMemoryKVRepository";
export * from "./InMemoryTaskOutputRepository";
export * from "./InMemoryTaskGraphRepository";
export * from "./InMemoryJobQueue";
export * from "./InMemoryRateLimiter";
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

import { describe, expect, it, beforeEach } from "bun:test";
import { rmdirSync } from "fs";
import { SingleTask, TaskOutput } from "../../task/base/Task";
import { DataFlow, TaskGraph } from "../../task/base/TaskGraph";
import { TaskRegistry } from "../../task";
import { InMemoryTaskGraphRepository } from "../taskgraph/InMemoryTaskGraphRepository";
import { SingleTask, TaskOutput, DataFlow, TaskGraph, TaskRegistry } from "ellmers-core";
import { InMemoryTaskGraphRepository } from "../InMemoryTaskGraphRepository";

class TestTask extends SingleTask {
static readonly type = "TestTask";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// *******************************************************************************

import { describe, expect, it, beforeEach } from "bun:test";
import { InMemoryTaskOutputRepository } from "../taskoutput/InMemoryTaskOutputRepository";
import { TaskInput, TaskOutput } from "../../task/base/Task";
import { InMemoryTaskOutputRepository } from "../InMemoryTaskOutputRepository";
import { TaskInput, TaskOutput } from "ellmers-core";

describe("InMemoryTaskOutputRepository", () => {
let repository: InMemoryTaskOutputRepository;
Expand Down

0 comments on commit e133784

Please sign in to comment.