-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuniversalSummarizer.go
61 lines (50 loc) · 1.34 KB
/
universalSummarizer.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
56
57
58
59
60
61
package kagi
import (
"fmt"
"github.com/httpjamesm/kagigo/types"
)
type SummaryType string
const (
SummaryTypeSummary SummaryType = "summary"
SummaryTypeTakeaways SummaryType = "takeaway"
)
type SummaryEngine string
const (
SummaryEngineCecil SummaryEngine = "cecil"
SummaryEngineAgnes SummaryEngine = "agnes"
SummaryEngineDaphne SummaryEngine = "daphne"
SummaryEngineMuriel SummaryEngine = "muriel"
)
type UniversalSummarizerParams struct {
URL string `json:"url"`
SummaryType SummaryType `json:"summary_type"`
Engine SummaryEngine `json:"engine"`
}
type UniversalSummarizerResponse struct {
Meta struct {
ID string `json:"id"`
Node string `json:"node"`
Ms int `json:"ms"`
} `json:"meta"`
Data struct {
Output string `json:"output"`
Tokens int `json:"tokens"`
} `json:"data"`
Errors []types.Error `json:"error"`
}
func (c *Client) UniversalSummarizerCompletion(params UniversalSummarizerParams) (res UniversalSummarizerResponse, err error) {
if params.URL == "" {
err = fmt.Errorf("url is required")
return
}
err = c.SendRequest("POST", "/summarize", params, &res)
if err != nil {
return
}
if len(res.Errors) != 0 {
errObj := res.Errors[0]
err = fmt.Errorf("api returned error: %v", fmt.Sprintf("[code: %d, msg: %s, ref: %v]", errObj.Code, errObj.Msg, errObj.Ref))
return
}
return
}