Skip to content

Commit

Permalink
fix: always enable document parser when a pdf is present in the conve…
Browse files Browse the repository at this point in the history
…rsation
  • Loading branch information
nsarrazin committed Dec 18, 2024
1 parent 46b0272 commit 4574f42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion chart/env/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ envVars:
],
"outputComponent": "textbox",
"outputComponentIdx": 0,
"showOutput": false
"showOutput": false,
"isHidden": true
},
{
"_id": "000000000000000000000003",
Expand Down
14 changes: 13 additions & 1 deletion src/routes/conversation/[id]/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4574f42

Please sign in to comment.