summize call
This commit is contained in:
commit
f8222b6951
|
@ -0,0 +1,5 @@
|
|||
module ewintr.nl/matrix-kagisum
|
||||
|
||||
go 1.20
|
||||
|
||||
require golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
|
|
@ -0,0 +1,2 @@
|
|||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
|
||||
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Kagi struct {
|
||||
apiKey string
|
||||
baseURL string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func NewKagi(baseURL, apiKey string) *Kagi {
|
||||
return &Kagi{
|
||||
apiKey: apiKey,
|
||||
baseURL: baseURL,
|
||||
client: &http.Client{
|
||||
Timeout: 10 * time.Minute,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (k *Kagi) Summarize(sumURL string) (string, error) {
|
||||
queryURL := fmt.Sprintf("%s/summarize?engine=muriel&url=%s", k.baseURL, url.QueryEscape(sumURL))
|
||||
//queryURL = ""
|
||||
req, err := http.NewRequest("GET", queryURL, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Authorization", fmt.Sprintf("Bot %s", k.apiKey))
|
||||
|
||||
res, err := k.client.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
fmt.Println(res.Status)
|
||||
|
||||
resBody, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
fmt.Sprintf("response: %v", string(resBody))
|
||||
|
||||
return string(resBody), nil
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//logger := slog.New(slog.NewTextHandler(os.Stderr))
|
||||
apiKey := getParam("KAGI_API_KEY", "")
|
||||
fmt.Println(apiKey)
|
||||
|
||||
k := NewKagi("https://kagi.com/api/v0", apiKey)
|
||||
|
||||
res, err := k.Summarize("https://ewintr.nl/shitty-ssg/why-i-built-my-own-shitty-static-site-generator/")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println(res)
|
||||
}
|
||||
|
||||
func getParam(param, def string) string {
|
||||
if val, ok := os.LookupEnv(param); ok {
|
||||
return val
|
||||
}
|
||||
return def
|
||||
}
|
Loading…
Reference in New Issue