Skip to content

Commit f82f7da

Browse files
committed
fix(search): align PDF options with API
1 parent 783d96b commit f82f7da

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,14 @@ const res = await sgai.search({
155155
timeRange: "past_week", // optional
156156
locationGeoCode: "us", // optional
157157
fetchConfig: { /* ... */ }, // optional
158-
contentTypes: [ // optional, defaults to text-like types
159-
"text/html",
160-
"application/json",
161-
"text/markdown",
162-
"text/plain",
163-
],
158+
allowedTypes: ["text/html", "application/pdf"], // optional MIME allowlist
159+
processors: [{ type: "pdf", maxPages: 10 }], // optional PDF page cap
164160
});
165161
```
166162

167-
By default `search` only scrapes text-like results (`text/html`, `application/json`,
168-
`text/markdown`, `text/plain`); PDFs, office documents and images are skipped. Pass
169-
`contentTypes` to change that, for example `contentTypes: ["text/html", "application/pdf"]`
170-
to include PDFs.
163+
By default `search` accepts every supported content type, including PDFs, and processes up to 25
164+
pages per PDF. Use `allowedTypes` to restrict accepted MIME types. Configure PDF processing
165+
separately with `processors`; `maxPages` accepts `1``500`, or `-1` for no page limit.
171166

172167
### crawl
173168

src/schemas.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const fetchContentTypeSchema = z.enum([
3030
"application/rtf",
3131
"application/vnd.oasis.opendocument.text",
3232
]);
33+
export const pdfProcessorSchema = z.object({
34+
type: z.literal("pdf"),
35+
maxPages: z.union([z.literal(-1), z.number().int().min(1).max(500)]).default(25),
36+
});
3337
export const userPromptSchema = z.string().min(1).max(10_000);
3438

3539
const PUBLIC_DOMAIN_RE =
@@ -250,7 +254,8 @@ export const searchRequestSchema = z
250254
prompt: userPromptSchema.optional(),
251255
schema: z.record(z.string(), z.unknown()).optional(),
252256
locationGeoCode: z.string().max(10).optional(),
253-
contentTypes: z.array(fetchContentTypeSchema).optional(),
257+
allowedTypes: z.array(fetchContentTypeSchema).min(1).optional(),
258+
processors: z.array(pdfProcessorSchema).min(1).optional(),
254259
timeRange: z
255260
.enum(["past_hour", "past_24_hours", "past_week", "past_month", "past_year"])
256261
.optional(),

tests/scrapegraphai.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,25 @@ describe("search", () => {
710710
expect(res.status).toBe("success");
711711
expectRequest(0, "POST", "/search", searchParams);
712712
});
713+
714+
test("with PDF options", async () => {
715+
const body = {
716+
results: [],
717+
metadata: { search: {}, pages: { requested: 1, scraped: 0 } },
718+
};
719+
fetchSpy = spyOn(globalThis, "fetch").mockResolvedValueOnce(json(body));
720+
const searchParams = {
721+
query: "papers",
722+
numResults: 1,
723+
allowedTypes: ["application/pdf"] as const,
724+
processors: [{ type: "pdf" as const, maxPages: 10 }],
725+
};
726+
727+
const res = await sdk.search(API_KEY, searchParams);
728+
729+
expect(res.status).toBe("success");
730+
expectRequest(0, "POST", "/search", searchParams);
731+
});
713732
});
714733

715734
describe("getCredits", () => {

0 commit comments

Comments
 (0)