Spaces:
Runtime error
Runtime error
Download apps/webapp/app/trigger/utils/queue.ts from BTankut/Context-Store-LLM: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/BTankut/Context-Store-LLM/resolve/main/apps/webapp/app/trigger/utils/queue.ts
- Command line
-
hf download hf://spaces/BTankut/Context-Store-LLM/apps/webapp/app/trigger/utils/queue.ts
-
curl -L -o queue.ts https://huggingface.co/spaces/BTankut/Context-Store-LLM/resolve/main/apps/webapp/app/trigger/utils/queue.ts
1.18 kB
| import { IngestionStatus, PrismaClient } from "@prisma/client"; | |
| import { type z } from "zod"; | |
| import { type IngestBodyRequest, ingestTask } from "../ingest/ingest"; | |
| const prisma = new PrismaClient(); | |
| export const addToQueue = async ( | |
| body: z.infer<typeof IngestBodyRequest>, | |
| userId: string, | |
| activityId?: string, | |
| ) => { | |
| const user = await prisma.user.findFirst({ | |
| where: { | |
| id: userId, | |
| }, | |
| include: { | |
| Workspace: true, | |
| }, | |
| }); | |
| if (!user?.Workspace?.id) { | |
| throw new Error( | |
| "Workspace ID is required to create an ingestion queue entry.", | |
| ); | |
| } | |
| const queuePersist = await prisma.ingestionQueue.create({ | |
| data: { | |
| spaceId: body.spaceId ? body.spaceId : null, | |
| data: body, | |
| status: IngestionStatus.PENDING, | |
| priority: 1, | |
| workspaceId: user.Workspace.id, | |
| activityId, | |
| }, | |
| }); | |
| const handler = await ingestTask.trigger( | |
| { body, userId, workspaceId: user.Workspace.id, queueId: queuePersist.id }, | |
| { | |
| queue: "ingestion-queue", | |
| concurrencyKey: userId, | |
| tags: [user.id, queuePersist.id], | |
| }, | |
| ); | |
| return { id: handler.id, token: handler.publicAccessToken }; | |
| }; | |