// PDFDetector(veridrop detectors/pdf.py):发一份单页测试 PDF(base64 document 块),要模型读出里面的暗号。 // 去掉多模态、降级成纯文本转发、或者直接报错的中转站都过不了。 import { TEST_DOCUMENT_PDF_B64 } from "../data/test_document_pdf.js"; import type { DetectorResult } from "../models.js"; import { cpSlice, joinText } from "../py.js"; import { ActiveDetector, errText, type DetectClient } from "./base.js"; export const MAGIC = "MAGIC-7F3K-VERIFY-CLAUDE-RELAY-DETECTOR"; const MAX_TOKENS = 150; const PROMPT = "What unique identifier string appears in this document? Reply with only the identifier string and no other text."; export class PDFDetector extends ActiveDetector { readonly name = "pdf"; readonly displayName = "PDF文档识别"; readonly weight = 8; async run(client: DetectClient, model: string): Promise { let resp: Record; try { ({ resp } = await client.messagesCreate({ model, max_tokens: MAX_TOKENS, temperature: 0, messages: [ { role: "user", content: [ { type: "document", source: { type: "base64", media_type: "application/pdf", data: TEST_DOCUMENT_PDF_B64 } }, { type: "text", text: PROMPT }, ], }, ], })); } catch (e) { // 中转站不收 document 块与网络错误一样记 0 分,状态是 fail(不是 error)。 return this.result("fail", 0, { phase: "request" }, null, errText(e)); } const text = joinText(resp["content"]); let score: number; let note: string; if (text.includes(MAGIC)) [score, note] = [100, "magic_found"]; else if (text.trim()) [score, note] = [50, "responded_but_missed_magic"]; else [score, note] = [0, "empty_response"]; return this.result(score >= 70 ? "pass" : "fail", score, { magic_string: MAGIC, response_text: cpSlice(text, 300), evaluation: note, stop_reason: resp["stop_reason"] ?? null, }); } }