-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummary.go
55 lines (42 loc) · 1.37 KB
/
summary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package brave
import (
"context"
"net/http"
"github.com/google/go-querystring/query"
)
func (b *brave) SummarizerSearch(ctx context.Context, key string, options ...SearchOption) (*SummarizerSearchResult, error) {
u := *b.baseURL
u.Path = u.Path + summarizerSearchPath
var opts searchOptions
applyOpts(&opts, options, nil)
var params summarizerSearchParams
params.fromSearchOptions(key, opts)
values, err := query.Values(params)
if err != nil {
return nil, err
}
u.RawQuery = values.Encode()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
opts.applyRequestHeaders(b.subscriptionToken, req)
return handleRequest[SummarizerSearchResult](b.client, req)
}
type SummarizerSearchResult struct {
Type string `json:"type"`
Status string `json:"status"`
Title string `json:"title"`
Summary []SummaryMessage `json:"summary"`
Enrichments *SummaryEnrichments `json:"enrichments"`
Followups []string `json:"followups"`
EntitiesInfo map[string]any `json:"entities_info"`
}
type summarizerSearchParams struct {
Key string `url:"key"`
EntityInfo bool `url:"entity_info"`
}
func (s *summarizerSearchParams) fromSearchOptions(key string, options searchOptions) {
s.Key = key
s.EntityInfo = options.entityInfo
}