Documentation
¶
Index ¶
- Constants
- Variables
- func OneShot(ctx context.Context, token, from, to, text string) (string, error)
- type AuthResponse
- type DetectParams
- type DetectResponse
- type Kagi
- func (kt *Kagi) Detect(ctx context.Context, text string) (DetectResponse, error)
- func (kt *Kagi) DetectWithParams(ctx context.Context, params DetectParams) (DetectResponse, error)
- func (kt *Kagi) Quota(ctx context.Context) (QuotaResponse, error)
- func (kt *Kagi) Translate(ctx context.Context, from, to, text string) (TranslateResponse, error)
- func (kt *Kagi) TranslateWithParams(ctx context.Context, params TranslateParams) (TranslateResponse, error)
- type Language
- type Option
- type Quota
- type QuotaResponse
- type TranslateParams
- type TranslateResponse
Constants ¶
const ( // DefaultUserAgent identifies this unofficial client to Kagi. DefaultUserAgent = "" /* 153-byte string literal not displayed */ )
Variables ¶
var ErrEmptyResponse = errors.New("empty response")
Functions ¶
Types ¶
type AuthResponse ¶
type AuthResponse struct {
Token string `json:"token"`
ID string `json:"id"`
LoggedIn bool `json:"loggedIn"`
Subscription bool `json:"subscription"`
ExpiresAt time.Time `json:"expiresAt"`
Theme string `json:"theme"`
MobileTheme string `json:"mobileTheme"`
CustomCSSEnabled bool `json:"customCssEnabled"`
Language string `json:"language"`
CustomCSSAvailable bool `json:"customCssAvailable"`
AccountType string `json:"accountType"`
Platform string `json:"platform"`
}
AuthResponse is returned by Kagi's auth endpoint.
type DetectParams ¶
type DetectParams struct {
Text string `json:"text"`
IncludeAlternatives bool `json:"include_alternatives"`
RecentLanguages []string `json:"recent_languages,omitempty"`
SessionToken string `json:"session_token,omitempty"`
}
DetectParams contains the request body sent to Kagi's detect endpoint.
type DetectResponse ¶
type DetectResponse struct {
DetectedLanguage Language `json:"detected_language"`
Alternatives []Language `json:"alternatives,omitempty"`
}
DetectResponse is returned by Kagi's detect endpoint.
type Kagi ¶
type Kagi struct {
// contains filtered or unexported fields
}
Kagi is a client for Kagi Translate's private web API.
func (*Kagi) DetectWithParams ¶
func (kt *Kagi) DetectWithParams(ctx context.Context, params DetectParams) (DetectResponse, error)
DetectWithParams detects the language of text using the provided options.
func (*Kagi) Quota ¶
func (kt *Kagi) Quota(ctx context.Context) (QuotaResponse, error)
Quota returns the authenticated account's Kagi Translate quota usage.
func (*Kagi) Translate ¶
Translate translates text from one language to another using standard options.
func (*Kagi) TranslateWithParams ¶
func (kt *Kagi) TranslateWithParams(ctx context.Context, params TranslateParams) (TranslateResponse, error)
TranslateWithParams translates text using the provided low-level options.
type Option ¶ added in v1.1.0
type Option func(*Kagi)
Option configures a Kagi client at construction time.
func WithClient ¶ added in v1.1.0
WithClient configures the HTTP client used for requests.
func WithUserAgent ¶ added in v1.1.0
WithUserAgent configures the User-Agent header used for requests.
type Quota ¶
type Quota struct {
Kind string `json:"kind"`
Used int `json:"used"`
Limit int `json:"limit"`
Remaining int `json:"remaining"`
Percent float64 `json:"percent"`
Exceeded bool `json:"exceeded"`
ResetsAt time.Time `json:"resetsAt"`
Exempt bool `json:"exempt"`
ActiveJobID *string `json:"activeJobId,omitempty"`
}
Quota describes usage for one Kagi Translate quota bucket.
type QuotaResponse ¶
type QuotaResponse struct {
Translate Quota `json:"translate"`
Proofread Quota `json:"proofread"`
Document Quota `json:"document"`
}
QuotaResponse is returned by Kagi's quota endpoint.
type TranslateParams ¶
type TranslateParams struct {
Text string `json:"text"`
From string `json:"from"`
To string `json:"to"`
Stream bool `json:"stream"`
PredictedLanguage string `json:"predicted_language,omitempty"`
Formality string `json:"formality"`
SpeakerGender string `json:"speaker_gender"`
AddresseeGender string `json:"addressee_gender"`
LanguageComplexity string `json:"language_complexity"`
TranslationStyle string `json:"translation_style"`
Context string `json:"context"`
Model string `json:"model"`
SessionToken string `json:"session_token"`
DictionaryLanguage string `json:"dictionary_language"`
UseDefinitionContext bool `json:"use_definition_context"`
EnableLanguageFeatures bool `json:"enable_language_features"`
}
TranslateParams contains the request body sent to Kagi's translate endpoint.
type TranslateResponse ¶
type TranslateResponse struct {
Translation string `json:"translation"`
DetectedLanguage Language `json:"detected_language"`
Definition struct {
Word string `json:"word"`
PrimaryMeaning struct {
Definition string `json:"definition"`
PartOfSpeech []string `json:"part_of_speech"`
PartOfSpeechCanonical []string `json:"part_of_speech_canonical"`
UsageLevel []string `json:"usage_level"`
Synonyms []string `json:"synonyms"`
SynonymComparisons []struct {
Synonym string `json:"synonym"`
Difference string `json:"difference"`
} `json:"synonym_comparisons,omitempty"`
} `json:"primary_meaning"`
SecondaryMeanings []struct {
Definition string `json:"definition"`
PartOfSpeech []string `json:"part_of_speech"`
PartOfSpeechCanonical []string `json:"part_of_speech_canonical"`
UsageLevel []string `json:"usage_level"`
Synonyms []string `json:"synonyms"`
SynonymComparisons []struct {
Synonym string `json:"synonym"`
Difference string `json:"difference"`
} `json:"synonym_comparisons,omitempty"`
} `json:"secondary_meanings"`
Examples []string `json:"examples"`
Pronunciation string `json:"pronunciation"`
Etymology string `json:"etymology"`
Notes string `json:"notes"`
TemporalTrend string `json:"temporal_trend"`
RelatedWords []struct {
Word string `json:"word"`
Relationship string `json:"relationship"`
} `json:"related_words"`
} `json:"definition"`
}
TranslateResponse is returned by Kagi's translate endpoint.