Skip to content

Commit ebdccc7

Browse files
committed
feat(pdf-summarizer): enhance PDF drop field functionality and improve summarization output formatting
1 parent edd223b commit ebdccc7

4 files changed

Lines changed: 31 additions & 17 deletions

File tree

app/src/app/tools/[toolId]/page.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ function PdfDropField({
317317
>("idle");
318318
const [fileName, setFileName] = useState<string>("");
319319
const [extractError, setExtractError] = useState<string>("");
320+
const [source, setSource] = useState<"file" | "manual">("manual");
320321

321322
const maxBytes = (config.maxSizeMb || 20) * 1024 * 1024;
322323

@@ -554,6 +555,7 @@ function PdfDropField({
554555
const text = await extractText(file);
555556
if (!text.trim()) throw new Error("No readable text found in this file.");
556557
onChange(text);
558+
setSource("file"); // Track that this value came from a file
557559
setDropState("done");
558560
} catch (err) {
559561
setExtractError(err instanceof Error ? err.message : "Unknown error.");
@@ -595,6 +597,7 @@ function PdfDropField({
595597
setFileName("");
596598
setDropState("idle");
597599
setExtractError("");
600+
setSource("manual"); // Reset to manual mode when cleared
598601
}, [onChange]);
599602

600603
const isLoading =
@@ -762,20 +765,23 @@ function PdfDropField({
762765
</button>
763766
)}
764767

765-
<div className="space-y-1">
766-
<p className="text-xs text-muted-foreground">Or paste / type text directly:</p>
767-
<Textarea
768-
value={value}
769-
onChange={(e) => {
770-
onChange(e.target.value);
771-
if (e.target.value && dropState === "idle") setDropState("done");
772-
if (!e.target.value) setDropState("idle");
773-
}}
774-
placeholder={config.placeholder}
775-
rows={config.rows || 14}
776-
className="resize-none font-mono text-xs"
777-
/>
778-
</div>
768+
{/* Only show the paste textarea when the user is typing, not when a file was loaded */}
769+
{source === "manual" && (
770+
<div className="space-y-1">
771+
<p className="text-xs text-muted-foreground">Or paste / type text directly:</p>
772+
<Textarea
773+
value={value}
774+
onChange={(e) => {
775+
onChange(e.target.value);
776+
if (e.target.value && dropState === "idle") setDropState("done");
777+
if (!e.target.value) setDropState("idle");
778+
}}
779+
placeholder={config.placeholder}
780+
rows={config.rows || 14}
781+
className="resize-none font-mono text-xs"
782+
/>
783+
</div>
784+
)}
779785
</div>
780786
);
781787
}

services/python-tools/tools/pdf-summarizer/summarizer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import os
3+
import re
34
from typing import Optional
45

56
from openai import AsyncOpenAI
@@ -31,7 +32,9 @@ async def _summarize_one(chunk: str, index: int, focus: Optional[str] = None) ->
3132
max_tokens=600,
3233
)
3334

34-
return response.choices[0].message.content.strip()
35+
raw = response.choices[0].message.content or ""
36+
cleaned = re.sub(r"<think>[\s\S]*?</think>", "", raw, flags=re.IGNORECASE).strip()
37+
return cleaned
3538

3639

3740
async def summarize_chunks(chunks: list, focus: str = "") -> list:

services/python-tools/tools/pdf-summarizer/synthesis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23

34
from openai import AsyncOpenAI
45

@@ -33,6 +34,8 @@
3334
- Never hallucinate figures. Use only data from the provided summaries and entities.
3435
- Preserve exact numbers, dates, and amounts.
3536
- Be concise and professional.
37+
- Start your response DIRECTLY with "## Executive Summary" — no preamble, no intro sentence.
38+
- Do NOT include any reasoning, chain-of-thought, or <think> blocks. Output only the final report.
3639
"""
3740

3841

@@ -107,4 +110,6 @@ async def synthesize(chunk_summaries: list, entities: list, structure: dict) ->
107110
temperature=0.2,
108111
)
109112

110-
return response.choices[0].message.content.strip()
113+
raw = response.choices[0].message.content or ""
114+
cleaned = re.sub(r"<think>[\s\S]*?</think>", "", raw, flags=re.IGNORECASE).strip()
115+
return cleaned

services/python-tools/tools/pdf-summarizer/tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async def stream():
5959

6060
yield "[synthesis] Building final report...\n"
6161
final_output = await synthesize(chunk_summaries, entities, structure)
62-
yield "\n---RESULT---\n"
62+
yield "\n---REPORT_START---\n"
6363
yield final_output
6464

6565
return stream()

0 commit comments

Comments
 (0)