kagi

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2024 License: MIT Imports: 7 Imported by: 2

README

kagigo

An unofficial Kagi API client for Go.

Installation

go get -u github.com/httpjamesm/kagigo

Quick Start

Client
client := kagi.NewClient(&kagi.ClientConfig{
    APIKey:     os.Getenv("KAGI_API_KEY"),
    APIVersion: "v0",
})
FastGPT
response, err := client.FastGPTCompletion(kagi.FastGPTCompletionParams{
    Query:     "query",
    WebSearch: true,
    Cache:     true,
})
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(response.Data.Output)
Universal Summarizer
response, err := client.UniversalSummarizerCompletion(kagi.UniversalSummarizerParams{
    URL:         "https://blog.kagi.com/security-audit",
    SummaryType: kagi.SummaryTypeSummary,
    Engine:      kagi.SummaryEngineCecil,
})
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(response.Data.Output)
Enrichment
response, err := client.EnrichmentCompletion(kagi.EndpointTypeWeb, kagi.EnrichmentParams{
    Q: "kagi search",
})
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(response.Data)

Documentation

Index

Constants

View Source
const (
	EndpointTypeWeb  string = "web"
	EndpointTypeNews string = "news"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Config *ClientConfig
}

func NewClient

func NewClient(config *ClientConfig) *Client

func (*Client) EnrichmentCompletion added in v0.0.6

func (c *Client) EnrichmentCompletion(endpointType string, params EnrichmentParams) (res EnrichmentResponse, err error)

func (*Client) FastGPTCompletion

func (c *Client) FastGPTCompletion(params FastGPTCompletionParams) (res FastGPTCompletionResponse, err error)

func (*Client) GetAPIKey

func (c *Client) GetAPIKey() string

func (*Client) GetAPIVersion

func (c *Client) GetAPIVersion() constants.ApiVersion

func (*Client) SendRequest

func (c *Client) SendRequest(method, path string, data interface{}, v any) (err error)

func (*Client) SetAPIKey

func (c *Client) SetAPIKey(apiKey string)

func (*Client) SetAPIVersion

func (c *Client) SetAPIVersion(apiVersion constants.ApiVersion)

func (*Client) UniversalSummarizerCompletion added in v0.0.2

func (c *Client) UniversalSummarizerCompletion(params UniversalSummarizerParams) (res UniversalSummarizerResponse, err error)

type ClientConfig

type ClientConfig struct {
	APIKey     string
	APIVersion constants.ApiVersion
}

type EnrichmentParams added in v0.0.6

type EnrichmentParams struct {
	Q string `json:"q"`
}

type EnrichmentResponse added in v0.0.6

type EnrichmentResponse struct {
	Meta struct {
		ID   string  `json:"id"`
		Node string  `json:"node"`
		Ms   int     `json:"ms"`
		API  float64 `json:"api_balance"`
	} `json:"meta"`
	Data []struct {
		T         int      `json:"t"`
		Rank      int      `json:"rank"`
		URL       string   `json:"url"`
		Title     string   `json:"title"`
		Snippet   string   `json:"snippet"`
		Published string   `json:"published"`
		List      []string `json:"list"`
	} `json:"data"`
	Errors []types.Error `json:"error"`
}

type FastGPTCompletionParams

type FastGPTCompletionParams struct {
	Query     string `json:"query"`
	WebSearch bool   `json:"web_search"`
	Cache     bool   `json:"cache"`
}

type FastGPTCompletionResponse

type FastGPTCompletionResponse struct {
	Meta struct {
		ID         string  `json:"id"`
		Node       string  `json:"node"`
		Ms         int     `json:"ms"`
		APIBalance float64 `json:"api_balance"`
	} `json:"meta"`
	Data struct {
		Output     string `json:"output"`
		Tokens     int    `json:"tokens"`
		References []struct {
			Title   string `json:"title"`
			Snippet string `json:"snippet"`
			URL     string `json:"url"`
		} `json:"references"`
	} `json:"data"`
	Errors []types.Error `json:"error"`
}

type SummaryEngine added in v0.0.2

type SummaryEngine string
const (
	SummaryEngineCecil  SummaryEngine = "cecil"
	SummaryEngineAgnes  SummaryEngine = "agnes"
	SummaryEngineDaphne SummaryEngine = "daphne"
	SummaryEngineMuriel SummaryEngine = "muriel"
)

type SummaryType added in v0.0.2

type SummaryType string
const (
	SummaryTypeSummary   SummaryType = "summary"
	SummaryTypeTakeaways SummaryType = "takeaway"
)

type UniversalSummarizerParams added in v0.0.2

type UniversalSummarizerParams struct {
	URL         string        `json:"url"`
	SummaryType SummaryType   `json:"summary_type"`
	Engine      SummaryEngine `json:"engine"`
}

type UniversalSummarizerResponse added in v0.0.2

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"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL