EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
llmQueue.js
Go to the documentation of this file.
1// llmQueue.js - BullMQ queue for LLM tasks
2const { Queue, Worker } = require('bullmq');
3const Redis = require('ioredis');
4const redisConfig = require('../config/redis');
5const redis = new Redis({
6 ...redisConfig,
7 maxRetriesPerRequest: null // BullMQ requires this to be null
8});
9
10const llmQueue = new Queue('llm-tasks', { connection: redis });
11
12// Worker: process rewrite/summarize jobs using llama.cpp
13const { callLlama } = require('./llamaCppService');
14const { setCachedLLMResult } = require('./llmRedis');
15const { addTenantHistory, setTenantSummary } = require('./llmTenantContext');
16
17const llmWorker = new Worker('llm-tasks', async job => {
18 const { type = 'rewrite', text, tenantId, docId } = job.data;
19 const result = await callLlama(text, type);
20 await setCachedLLMResult(type, text, result);
21 if (tenantId && docId) {
22 await addTenantHistory(tenantId, docId, text);
23 if (type === 'summary') await setTenantSummary(tenantId, docId, result);
24 }
25 return { result };
26}, { connection: redis });
27
28module.exports = { llmQueue, llmWorker };