mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-10 23:58:28 +00:00
* feat: remove trigger and run base on bullmq * fix: telemetry and trigger deploymen * feat: add Ollama container and update ingestion status for unchanged documents * feat: add logger to bullmq workers * 1. Remove chat and deep-search from trigger 2. Add ai/sdk for chat UI 3. Added a better model manager * refactor: simplify clustered graph query and add stop conditions for AI responses * fix: streaming * fix: docker docs --------- Co-authored-by: Manoj <saimanoj58@gmail.com>
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import { conversationTitlePrompt } from "~/trigger/conversation/prompt";
|
|
import { prisma } from "~/trigger/utils/prisma";
|
|
import { logger } from "~/services/logger.service";
|
|
import { generateText, type LanguageModel } from "ai";
|
|
import { getModel } from "~/lib/model.server";
|
|
|
|
export interface CreateConversationTitlePayload {
|
|
conversationId: string;
|
|
message: string;
|
|
}
|
|
|
|
export interface CreateConversationTitleResult {
|
|
success: boolean;
|
|
title?: string;
|
|
error?: string;
|
|
}
|
|
|
|
/**
|
|
* Core business logic for creating conversation titles
|
|
* This is shared between Trigger.dev and BullMQ implementations
|
|
*/
|
|
export async function processConversationTitleCreation(
|
|
payload: CreateConversationTitlePayload,
|
|
): Promise<CreateConversationTitleResult> {
|
|
try {
|
|
let conversationTitleResponse = "";
|
|
const { text } = await generateText({
|
|
model: getModel() as LanguageModel,
|
|
messages: [
|
|
{
|
|
role: "user",
|
|
content: conversationTitlePrompt.replace(
|
|
"{{message}}",
|
|
payload.message,
|
|
),
|
|
},
|
|
],
|
|
});
|
|
|
|
const outputMatch = text.match(/<output>(.*?)<\/output>/s);
|
|
|
|
logger.info(`Conversation title data: ${JSON.stringify(outputMatch)}`);
|
|
|
|
if (!outputMatch) {
|
|
logger.error("No output found in recurrence response");
|
|
throw new Error("Invalid response format from AI");
|
|
}
|
|
|
|
const jsonStr = outputMatch[1].trim();
|
|
const conversationTitleData = JSON.parse(jsonStr);
|
|
|
|
if (conversationTitleData) {
|
|
await prisma.conversation.update({
|
|
where: {
|
|
id: payload.conversationId,
|
|
},
|
|
data: {
|
|
title: conversationTitleData.title,
|
|
},
|
|
});
|
|
|
|
return {
|
|
success: true,
|
|
title: conversationTitleData.title,
|
|
};
|
|
}
|
|
|
|
return {
|
|
success: false,
|
|
error: "No title generated",
|
|
};
|
|
} catch (error: any) {
|
|
logger.error(
|
|
`Error creating conversation title for ${payload.conversationId}:`,
|
|
error,
|
|
);
|
|
return {
|
|
success: false,
|
|
error: error.message,
|
|
};
|
|
}
|
|
}
|