Skip to content

Commit b5ffb30

Browse files
author
stlc-bot
committed
feat(search): add highlights to web search and bill page reads per 10 results (#1387)
Stainless-Generated-From: 7d693fe87de6b88c0cba43bc1c5ac60958ece31c
1 parent 1cf2e4a commit b5ffb30

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎pkg/cmd/web.go‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ var webScreenshot = requestflag.WithInnerFlags(cli.Command{
302302

303303
var webSearch = requestflag.WithInnerFlags(cli.Command{
304304
Name: "search",
305-
Usage: "Search the web and optionally return page content with each result.",
305+
Usage: "Search the web and optionally return page content or relevant passages with each\nresult.",
306306
Suggest: true,
307307
Flags: []cli.Flag{
308308
&requestflag.Flag[string]{
@@ -326,6 +326,11 @@ var webSearch = requestflag.WithInnerFlags(cli.Command{
326326
Usage: "Restrict results to content published within this window.",
327327
BodyPath: "freshness",
328328
},
329+
&requestflag.Flag[map[string]any]{
330+
Name: "highlights-options",
331+
Usage: "Passages from each result page that are relevant to the query. Pages are read with the `markdownOptions` settings.",
332+
BodyPath: "highlightsOptions",
333+
},
329334
&requestflag.Flag[[]string]{
330335
Name: "include-domain",
331336
Usage: `Allowlist — only return results from these domains. Example: ["arxiv.org", "github.com"].`,
@@ -367,10 +372,22 @@ var webSearch = requestflag.WithInnerFlags(cli.Command{
367372
Action: handleWebSearch,
368373
HideHelpCommand: true,
369374
}, map[string][]requestflag.HasOuterFlag{
375+
"highlights-options": {
376+
&requestflag.InnerFlag[bool]{
377+
Name: "highlights-options.enabled",
378+
Usage: "Return relevant passages for each result. Adds 1 credit per 10 results.",
379+
InnerField: "enabled",
380+
},
381+
&requestflag.InnerFlag[int64]{
382+
Name: "highlights-options.max-characters",
383+
Usage: "Maximum combined length of passages per result.",
384+
InnerField: "maxCharacters",
385+
},
386+
},
370387
"markdown-options": {
371388
&requestflag.InnerFlag[bool]{
372389
Name: "markdown-options.enabled",
373-
Usage: "Scrape each result to Markdown. Off by default to keep search cheap and fast.",
390+
Usage: "Scrape each result to Markdown. Adds 1 credit per 10 results.",
374391
InnerField: "enabled",
375392
},
376393
&requestflag.InnerFlag[bool]{
@@ -390,7 +407,7 @@ var webSearch = requestflag.WithInnerFlags(cli.Command{
390407
},
391408
&requestflag.InnerFlag[int64]{
392409
Name: "markdown-options.max-age-ms",
393-
Usage: "Cache TTL in ms for scraped Markdown keyed by URL + options. Default 1 day, max 30 days. Set to 0 to force a fresh scrape.",
410+
Usage: "Cache TTL in ms for scraped Markdown keyed by URL + options. Default 15 days, max 30 days. Set to 0 to force a fresh scrape.",
394411
InnerField: "maxAgeMs",
395412
},
396413
&requestflag.InnerFlag[map[string]any]{

‎pkg/cmd/web_test.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func TestWebSearch(t *testing.T) {
215215
"--country", "af",
216216
"--exclude-domain", "string",
217217
"--freshness", "last_24_hours",
218+
"--highlights-options", "{enabled: true, maxCharacters: 100}",
218219
"--include-domain", "string",
219220
"--markdown-options", "{enabled: true, includeFrames: true, includeImages: true, includeLinks: true, maxAgeMs: 0, pdf: {end: 1, shouldParse: true, start: 1}, shortenBase64Images: true, timeoutOpts: {milliseconds: 1, behavior: fail}, useMainContentOnly: true, waitForMs: 0}",
220221
"--num-results", "10",
@@ -239,6 +240,8 @@ func TestWebSearch(t *testing.T) {
239240
"--country", "af",
240241
"--exclude-domain", "string",
241242
"--freshness", "last_24_hours",
243+
"--highlights-options.enabled=true",
244+
"--highlights-options.max-characters", "100",
242245
"--include-domain", "string",
243246
"--markdown-options.enabled=true",
244247
"--markdown-options.include-frames=true",
@@ -268,6 +271,9 @@ func TestWebSearch(t *testing.T) {
268271
"excludeDomains:\n" +
269272
" - string\n" +
270273
"freshness: last_24_hours\n" +
274+
"highlightsOptions:\n" +
275+
" enabled: true\n" +
276+
" maxCharacters: 100\n" +
271277
"includeDomains:\n" +
272278
" - string\n" +
273279
"markdownOptions:\n" +

0 commit comments

Comments
 (0)