From 4574f42607a5a1a25443efb5ccbae75d3bee5505 Mon Sep 17 00:00:00 2001 From: Nathan Sarrazin Date: Wed, 18 Dec 2024 15:36:27 +0000 Subject: [PATCH] fix: always enable document parser when a pdf is present in the conversation --- chart/env/prod.yaml | 3 ++- src/routes/conversation/[id]/+server.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/chart/env/prod.yaml b/chart/env/prod.yaml index 8e92c3d7b95..b63c3b47c39 100644 --- a/chart/env/prod.yaml +++ b/chart/env/prod.yaml @@ -511,7 +511,8 @@ envVars: ], "outputComponent": "textbox", "outputComponentIdx": 0, - "showOutput": false + "showOutput": false, + "isHidden": true }, { "_id": "000000000000000000000003", diff --git a/src/routes/conversation/[id]/+server.ts b/src/routes/conversation/[id]/+server.ts index a7ec44f6eb5..7bc07e12de8 100644 --- a/src/routes/conversation/[id]/+server.ts +++ b/src/routes/conversation/[id]/+server.ts @@ -25,6 +25,7 @@ import { MetricsServer } from "$lib/server/metrics"; import { textGeneration } from "$lib/server/textGeneration"; import type { TextGenerationContext } from "$lib/server/textGeneration/types"; import { logger } from "$lib/server/logger.js"; +import { documentParserToolId } from "$lib/utils/toolIds.js"; export async function POST({ request, locals, params, getClientAddress }) { const id = z.string().parse(params.id); @@ -190,6 +191,14 @@ export async function POST({ request, locals, params, getClientAddress }) { }) ); + // Check for PDF files in the input + const hasPdfFiles = inputFiles?.some((file) => file.mime === "application/pdf") ?? false; + + // Check for existing PDF files in the conversation + const hasPdfInConversation = + conv.messages?.some((msg) => msg.files?.some((file) => file.mime === "application/pdf")) ?? + false; + if (usageLimits?.messageLength && (newPrompt?.length ?? 0) > usageLimits.messageLength) { error(400, "Message too long."); } @@ -442,7 +451,10 @@ export async function POST({ request, locals, params, getClientAddress }) { assistant: undefined, isContinue: isContinue ?? false, webSearch: webSearch ?? false, - toolsPreference: toolsPreferences ?? [], + toolsPreference: [ + ...(toolsPreferences ?? []), + ...(hasPdfFiles || hasPdfInConversation ? [documentParserToolId] : []), // Add document parser tool if PDF files are present + ], promptedAt, ip: getClientAddress(), username: locals.user?.username,