Skip to content

Commit

Permalink
refactor: Move inference to the shared package
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Oct 26, 2024
1 parent db45aaf commit 3e727f7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apps/workers/openaiWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { and, Column, eq, inArray, sql } from "drizzle-orm";
import { z } from "zod";

import type { InferenceClient } from "@hoarder/shared/inference";
import type { ZOpenAIRequest } from "@hoarder/shared/queues";
import { db } from "@hoarder/db";
import {
Expand All @@ -13,6 +14,7 @@ import {
import { DequeuedJob, Runner } from "@hoarder/queue";
import { readAsset } from "@hoarder/shared/assetdb";
import serverConfig from "@hoarder/shared/config";
import { InferenceClientFactory } from "@hoarder/shared/inference";
import logger from "@hoarder/shared/logger";
import { buildImagePrompt, buildTextPrompt } from "@hoarder/shared/prompts";
import {
Expand All @@ -21,8 +23,6 @@ import {
zOpenAIRequestSchema,
} from "@hoarder/shared/queues";

import type { InferenceClient } from "./inference";
import { InferenceClientFactory } from "./inference";
import { readImageText, readPDFText } from "./utils";

const openAIResponseSchema = z.object({
Expand Down
2 changes: 0 additions & 2 deletions apps/workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"metascraper-title": "^5.45.22",
"metascraper-twitter": "^5.45.6",
"metascraper-url": "^5.45.22",
"ollama": "^0.5.9",
"openai": "^4.67.1",
"pdf2json": "^3.0.5",
"pdfjs-dist": "^4.0.379",
"puppeteer": "^22.0.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/workers/inference.ts → packages/shared/inference.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Ollama } from "ollama";
import OpenAI from "openai";

import serverConfig from "@hoarder/shared/config";
import logger from "@hoarder/shared/logger";
import serverConfig from "./config";
import logger from "./logger";

export interface InferenceResponse {
response: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"@hoarder/queue": "workspace:^0.1.0",
"glob": "^11.0.0",
"meilisearch": "^0.37.0",
"ollama": "^0.5.9",
"openai": "^4.67.1",
"winston": "^3.11.0",
"zod": "^3.22.4"
},
Expand Down
13 changes: 7 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e727f7

Please sign in to comment.