jigsawstack

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 10 Imported by: 0

README

jigsawstack

Documentation

Overview

Package jigsawstack provides a JigsawStack extension for pegwings-go.

It gives tools for working with the JigsawStack API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatasetEntry

type DatasetEntry struct {
	Date  time.Time `json:"date"`
	Value float64   `json:"value"`
}

DatasetEntry represents a dataset entry.

type Emotion

type Emotion string

Emotion is an emotion.

const (

	// EmotionAnger is the anger emotion.
	EmotionAnger Emotion = "anger"
	// EmotionFear is the fear emotion.
	EmotionFear Emotion = "fear"
	// EmotionSadness is the sadness emotion.
	EmotionSadness Emotion = "sadness"
	// EmotionHappiness is the happiness emotion.
	EmotionHappiness Emotion = "happiness"
	// EmotionAnxiety is the anxiety emotion.
	EmotionAnxiety Emotion = "anxiety"
	// EmotionDisgust is the disgust emotion.
	EmotionDisgust Emotion = "disgust"
	// EmotionEmbarrassment is the embarrassment emotion.
	EmotionEmbarrassment Emotion = "embarrassment"
	// EmotionLove is the love emotion.
	EmotionLove Emotion = "love"
	// EmotionSurprise is the surprise emotion.
	EmotionSurprise Emotion = "surprise"
	// EmotionShame is the shame emotion.
	EmotionShame Emotion = "shame"
	// EmotionEnvy is the envy emotion.
	EmotionEnvy Emotion = "envy"
	// EmotionSatisfaction is the satisfaction emotion.
	EmotionSatisfaction Emotion = "satisfaction"
	// EmotionSelfConfidence is the self-confidence emotion.
	EmotionSelfConfidence Emotion = "self-confidence"
	// EmotionAnnoyance is the annoyance emotion.
	EmotionAnnoyance Emotion = "annoyance"
	// EmotionBoredom is the boredom emotion.
	EmotionBoredom Emotion = "boredom"
	// EmotionHatred is the hatred emotion.
	EmotionHatred Emotion = "hatred"
	// EmotionCompassion is the compassion emotion.
	EmotionCompassion Emotion = "compassion"
	// EmotionGuilt is the guilt emotion.
	EmotionGuilt Emotion = "guilt"
	// EmotionLoneliness is the loneliness emotion.
	EmotionLoneliness Emotion = "loneliness"
	// EmotionDepression is the depression emotion.
	EmotionDepression Emotion = "depression"
	// EmotionPride is the pride emotion.
	EmotionPride Emotion = "pride"
	// EmotionNeutral is the neutral emotion.
	EmotionNeutral Emotion = "neutral"
)

type Endpoint

type Endpoint string

Endpoint is the endpoint for the JigsawStack api.

type GeographyRequest

type GeographyRequest struct {
	Query        string  `json:"query"`
	Country      string  `json:"country,omitempty"`
	Latitude     float64 `json:"latitude,omitempty"`
	ProximityLat float64 `json:"proximity_lat,omitempty"`
	Longitude    float64 `json:"longitude,omitempty"`
	ProximityLng float64 `json:"proximity_lng,omitempty"`
	Types        string  `json:"types,omitempty"`
}

GeographyRequest represents a request structure for geography API.

func (*GeographyRequest) URLQuery

func (r *GeographyRequest) URLQuery(url *url.URL)

URLQuery converts the params into params on the given url.

type GeographyResponse

type GeographyResponse struct {
	Success bool `json:"success"`
	Data    []struct {
		Type           string `json:"type"`
		FullAddress    string `json:"full_address"`
		Name           string `json:"name"`
		PlaceFormatted string `json:"place_formatted"`
		Postcode       string `json:"postcode"`
		Place          string `json:"place"`
		Region         struct {
			Name           string `json:"name"`
			RegionCode     string `json:"region_code"`
			RegionCodeFull string `json:"region_code_full"`
		} `json:"region"`
		Country struct {
			Name              string `json:"name"`
			CountryCode       string `json:"country_code"`
			CountryCodeAlpha3 string `json:"country_code_alpha_3"`
		} `json:"country"`
		Language string `json:"language"`
		Geoloc   struct {
			Type        string    `json:"type"`
			Coordinates []float64 `json:"coordinates"`
		} `json:"geoloc"`
		PoiCategory         []string `json:"poi_category"`
		AddtionalProperties struct {
			Phone     string `json:"phone"`
			Website   string `json:"website"`
			OpenHours struct {
			} `json:"open_hours"`
		} `json:"addtional_properties"`
	} `json:"data"`
}

GeographyResponse represents a response structure for geography API.

type ImageGenerationRequest

type ImageGenerationRequest struct {
	Prompt string `json:"prompt"`
	Model  string `json:"model,omitempty"`
	Size   string `json:"size"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

ImageGenerationRequest represents a request structure for image generation API.

type ImageGenerationResponse

type ImageGenerationResponse struct {
	Success bool   `json:"success"`
	Image   string `json:"image"`
}

ImageGenerationResponse represents a response structure for image generation API.

type JigsawStack

type JigsawStack struct {
	// contains filtered or unexported fields
}

JigsawStack is a JigsawStack extension.

func NewJigsawStack

func NewJigsawStack(apiKey string, opts ...Option) (*JigsawStack, error)

NewJigsawStack creates a new JigsawStack extension.

func (*JigsawStack) AudioTTS

func (j *JigsawStack) AudioTTS(
	ctx context.Context,
	text string,
	options ...TTSOption,
) (mp3 string, err error)

AudioTTS creates a text to speech (TTS) audio file.

It only support one option at a time, but does support no options.

POST https://api.jigsawstack.com/v1/ai/tts

https://docs.jigsawstack.com/api-reference/ai/text-to-speech

func (*JigsawStack) FileAdd

func (j *JigsawStack) FileAdd(
	ctx context.Context,
	key string,
	contentType string,
	content string,
) (string, error)

FileAdd uploads a file to the Jigsaw Stack file store.

https://docs.jigsawstack.com/api-reference/store/file/add

POST https://api.jigsawstack.com/v1/store/file

func (*JigsawStack) FileDelete

func (j *JigsawStack) FileDelete(fileName string) error

FileDelete deletes a file from the Jigsaw Stack file store.

https://docs.jigsawstack.com/api-reference/store/file/delete

DELETE https://api.jigsawstack.com/v1/store/file/{fileName}

func (*JigsawStack) FileGet

func (j *JigsawStack) FileGet(ctx context.Context, fileName string) (string, error)

FileGet retrieves a file from the Jigsaw Stack file store.

https://docs.jigsawstack.com/api-reference/store/file/get

GET https://api.jigsawstack.com/v1/store/file/{fileName}

func (*JigsawStack) GeographyGeocode

func (j *JigsawStack) GeographyGeocode(
	ctx context.Context,
	request GeographyRequest,
) (response GeographyResponse, err error)

GeographyGeocode performs a geography geocode api call over a query string.

GET https://api.jigsawstack.com/v1/geo/geocode

https://docs.jigsawstack.com/api-reference/geo/geocode

func (*JigsawStack) GeographySearch

func (j *JigsawStack) GeographySearch(
	ctx context.Context,
	request GeographyRequest,
) (response GeographyResponse, err error)

GeographySearch performs a geography search api call over a query string.

https://api.jigsawstack.com/v1/geo/search

https://docs.jigsawstack.com/api-reference/geo/search

func (*JigsawStack) ImageGeneration

func (j *JigsawStack) ImageGeneration(
	ctx context.Context,
	request ImageGenerationRequest,
) (response ImageGenerationResponse, err error)

ImageGeneration generates an image from a prompt and parameters.

func (*JigsawStack) KVAdd

func (j *JigsawStack) KVAdd(
	ctx context.Context,
	key string,
	value string,
) error

KVAdd adds a key value pair to the Jigsaw Stack key-value store.

https://docs.jigsawstack.com/api-reference/store/kv/add

POST https://api.jigsawstack.com/v1/store/kv

func (*JigsawStack) KVDelete

func (j *JigsawStack) KVDelete(
	ctx context.Context,
	key string,
) (string, error)

KVDelete deletes a key value pair from the Jigsaw Stack key-value store.

https://docs.jigsawstack.com/api-reference/store/kv/delete

DELETE https://api.jigsawstack.com/v1/store/kv/{key}

func (*JigsawStack) KVGet

func (j *JigsawStack) KVGet(
	ctx context.Context,
	key string,
) (string, error)

KVGet retrieves a key value pair from the Jigsaw Stack key-value store.

https://docs.jigsawstack.com/api-reference/store/kv/get

GET https://api.jigsawstack.com/v1/store/kv/{key}

func (*JigsawStack) Predict

func (j *JigsawStack) Predict(
	ctx context.Context,
	dataset []DatasetEntry,
) (response PredictResponse, err error)

Predict predicts the future values of a dataset.

Max text character is 5000.

func (*JigsawStack) PromptCreate

func (j *JigsawStack) PromptCreate(
	ctx context.Context,
	request PromptCreateRequest,
) (response PromptResponse, err error)

PromptCreate creates a prompt.

https://docs.jigsawstack.com/api-reference/prompt-engine/create

POST https://api.jigsawstack.com/v1/prompt_engine

func (*JigsawStack) PromptDelete

func (j *JigsawStack) PromptDelete(
	ctx context.Context,
	id string,
) (response PromptResponse, err error)

PromptDelete deletes a specific prompt.

https://api.jigsawstack.com/v1/prompt_engine/{id}

https://docs.jigsawstack.com/api-reference/prompt-engine/delete

func (*JigsawStack) PromptGet

func (j *JigsawStack) PromptGet(
	ctx context.Context,
	id string,
) (response PromptEngine, err error)

PromptGet gets a specific prompt.

GET https://api.jigsawstack.com/v1/prompt_engine/{id}

https://docs.jigsawstack.com/api-reference/prompt-engine/retrieve

func (*JigsawStack) PromptList

func (j *JigsawStack) PromptList(
	ctx context.Context,
	page int,
	limit int,
) (response PromptListResponse, err error)

PromptList lists prompts.

https://docs.jigsawstack.com/api-reference/prompt-engine/list

GET https://api.jigsawstack.com/v1/prompt_engine

func (*JigsawStack) PromptRun

func (j *JigsawStack) PromptRun(
	ctx context.Context,
	id string,
	inputs map[string]any,
) (response PromptRunResponse, err error)

PromptRun runs a specific prompt with the given inputs.

https://api.jigsawstack.com/v1/prompt_engine/{id}

https://docs.jigsawstack.com/api-reference/prompt-engine/run

func (*JigsawStack) PromptRunDirect

func (j *JigsawStack) PromptRunDirect(
	ctx context.Context,
	request PromptCreateRequest,
	inputs map[string]any,
) (response PromptRunResponse, err error)

PromptRunDirect runs new prompt with the given inputs.

https://docs.jigsawstack.com/api-reference/prompt-engine/run-direct

https://api.jigsawstack.com/v1/prompt_engine/run

func (*JigsawStack) Sentiment

func (j *JigsawStack) Sentiment(
	ctx context.Context,
	text string,
) (SentimentResponse, error)

Sentiment performs a sentiment api call over a string.

func (*JigsawStack) Summarize

func (j *JigsawStack) Summarize(
	ctx context.Context,
	request SummaryRequest,
) (response SummaryResponse, err error)

Summarize summarizes the give text.

Max text character is 5000.

func (*JigsawStack) TextToSQL

func (j *JigsawStack) TextToSQL(
	ctx context.Context,
	prompt string,
	sqlSchema string,
) (response TextToSQLResponse, err error)

TextToSQL converts the text to SQL.

Max text character is 5000.

func (*JigsawStack) Translate

func (j *JigsawStack) Translate(
	ctx context.Context,
	request TranslateRequest,
) (response TranslateResponse, err error)

Translate translates the text from the current language to the target language.

Max text character is 5000.

func (*JigsawStack) VOCR

func (j *JigsawStack) VOCR(
	ctx context.Context,
	prompt string,
	opt VCOROption,
) (string, error)

VOCR performs a visual object recognition (VOCR) task on an image.

POST https://api.jigsawstack.com/v1/vocr

https://docs.jigsawstac.com/api-reference/ai/vision

func (*JigsawStack) VisionObjectDetection

func (j *JigsawStack) VisionObjectDetection(
	ctx context.Context,
	params visionRequest,
) (string, error)

VisionObjectDetection performs a visual object detection (VOD) task on an image.

POST https://api.jigsawstack.com/v1/ai/object_detection

https://docs.jigsawstack.com/api-reference/ai/object-detection

func (*JigsawStack) WebSearch

func (j *JigsawStack) WebSearch(
	ctx context.Context,
	query string,
) (response WebSearchResponse, err error)

WebSearch performs a web search api call over a query string.

GET https://api.jigsawstack.com/v1/web/search

https://docs.jigsawstack.com/api-reference/web/search

func (*JigsawStack) WebSearchSuggestions

func (j *JigsawStack) WebSearchSuggestions(
	ctx context.Context,
	query string,
) (response WebSearchSuggestions, err error)

WebSearchSuggestions performs a web search suggestions api call over a query string.

GET https://api.jigsawstack.com/v1/web/search/suggest

https://docs.jigsawstack.com/api-reference/web/search

type Language

type Language string

Language is a language.

type Option

type Option func(*JigsawStack)

Option is an option for the JigsawStack client.

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the base URL for the JigsawStack extension.

func WithClient

func WithClient(client *http.Client) Option

WithClient sets the client for the JigsawStack extension.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger for the JigsawStack extension.

type PredictResponse

type PredictResponse struct {
	Success bool           `json:"success"`
	Answer  []DatasetEntry `json:"answer"`
}

PredictResponse represents a response structure for prediction API.

type PromptCreateInput

type PromptCreateInput struct {
	Key          string `json:"key"`
	Optional     bool   `json:"optional"`
	InitialValue string `json:"initial_value"`
}

PromptCreateInput represents an entry in a prompt create request.

type PromptCreateRequest

type PromptCreateRequest struct {
	Prompt       string              `json:"prompt"`
	Inputs       []PromptCreateInput `json:"inputs"`
	ReturnPrompt string              `json:"return_prompt"`
	PromptGuard  []string            `json:"prompt_guard"`
	Optimize     bool                `json:"optimize_prompt,omitempty"`
	UseInternet  bool                `json:"use_internet,omitempty"`
}

PromptCreateRequest represents a request structure for prompt create API.

type PromptEngine

type PromptEngine struct {
	ID           string    `json:"id"`
	Prompt       string    `json:"prompt"`
	Inputs       any       `json:"inputs"`
	ReturnPrompt any       `json:"return_prompt"`
	CreatedAt    time.Time `json:"created_at"`
}

PromptEngine represents a prompt engine.

type PromptListResponse

type PromptListResponse struct {
	Success       bool           `json:"success"`
	PromptEngines []PromptEngine `json:"prompt_engines"`
	Page          int            `json:"page"`
	Limit         int            `json:"limit"`
	HasMore       bool           `json:"has_more"`
}

PromptListResponse represents a response structure for prompt list API.

type PromptResponse

type PromptResponse struct {
	Success bool   `json:"success"`
	ID      string `json:"prompt_engine_id"`
}

PromptResponse represents a response structure for prompt create API.

type PromptRunResponse

type PromptRunResponse struct {
	Success bool   `json:"success"`
	Result  string `json:"result"`
}

PromptRunResponse represents a response structure for prompt run API.

type SentimentResponse

type SentimentResponse struct {
	Success   bool `json:"success"`
	Sentiment struct {
		Emotion   Emotion `json:"emotion"`
		Sentiment string  `json:"sentiment"`
		Score     float64 `json:"score"`
		Sentences []struct {
			Text      string  `json:"text"`
			Emotion   Emotion `json:"emotion"`
			Sentiment string  `json:"sentiment"`
			Score     float64 `json:"score"`
		} `json:"sentences"`
	} `json:"sentiment"`
}

SentimentResponse represents a response structure for sentiment API.

type StorageResponse

type StorageResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message,omitempty"`
	URL     string `json:"url"`
	Key     string `json:"key"`
	Value   string `json:"value,omitempty"`
}

StorageResponse represents a response structure for file API.

type SummaryRequest

type SummaryRequest struct {
	Text string `json:"text"`
}

SummaryRequest represents a request structure for summary API.

type SummaryResponse

type SummaryResponse struct {
	Success bool   `json:"success"`
	Summary string `json:"summary"`
}

SummaryResponse represents a response structure for summary API.

type TTSOption

type TTSOption func(*ttsRequest)

TTSOption is an option for the TTS request.

func WithAccent

func WithAccent(accent string) TTSOption

WithAccent sets the accent of the speaker voice to use.

func WithFileKey

func WithFileKey(key string) TTSOption

WithFileKey sets the file key of the speaker voice to use.

func WithSpeakerURL

func WithSpeakerURL(url string) TTSOption

WithSpeakerURL sets the url of the speaker voice to use.

type TextToSQLResponse

type TextToSQLResponse struct {
	Success bool   `json:"success"`
	SQL     string `json:"sql"`
}

TextToSQLResponse represents a response structure for text to SQL API.

type TranslateRequest

type TranslateRequest struct {
	CurrentLanguage Language `json:"current_language"`
	TargetLanguage  Language `json:"target_language"`
	Text            string   `json:"text"`
}

TranslateRequest represents a request structure for translate API.

type TranslateResponse

type TranslateResponse struct {
	Success        bool   `json:"success"`
	TranslatedText string `json:"translated_text"`
}

TranslateResponse represents a response structure for translate API.

type VCOROption

type VCOROption func(*visionRequest)

VCOROption is the option for VOCR.

func WithKey

func WithKey(key string) VCOROption

WithKey sets the key of the file to use as the image.

func WithURL

func WithURL(url string) VCOROption

WithURL sets the URL of the image to use as the image.

type VOCRResponse

type VOCRResponse struct {
	// Success is a boolean indicating whether the request was
	// successful.
	Success bool `json:"success"`
	// Context is the context of the image.
	Context string `json:"context"`
	// Width is the width of the image.
	Width int `json:"width"`
	// Height is the height of the image.
	Height int `json:"height"`
	// Tags is a list of tags detected in the image.
	Tags []string `json:"tags"`
	// HasText is a boolean indicating whether the image contains
	// text.
	HasText bool `json:"has_text"`
	// Sections is a list of sections detected in the image.
	Sections []any `json:"sections"`
}

VOCRResponse represents a response structure for VOCR API.

type VisionObjectResponse

type VisionObjectResponse struct {
	// Success is a boolean indicating whether the request was
	Success bool `json:"success"`
	// Width is the width of the image.
	Width int `json:"width"`
	// Height is the height of the image.
	Height int `json:"height"`
	// Tags is a list of tags detected in the image.
	Tags []string `json:"tags"`
	// Objects is a list of objects detected in the image.
	Objects []struct {
		Name       string  `json:"name"`
		Confidence float64 `json:"confidence"`
		Bounds     struct {
			TopLeft struct {
				X int `json:"x"`
				Y int `json:"y"`
			} `json:"top_left"`
			TopRight struct {
				X int `json:"x"`
				Y int `json:"y"`
			} `json:"top_right"`
			BottomRight struct {
				X int `json:"x"`
				Y int `json:"y"`
			} `json:"bottom_right"`
			BottomLeft struct {
				X int `json:"x"`
				Y int `json:"y"`
			} `json:"bottom_left"`
			Width  int `json:"width"`
			Height int `json:"height"`
		} `json:"bounds"`
	} `json:"objects"`
}

VisionObjectResponse represents a response structure for VOD API.

type WebSearchResponse

type WebSearchResponse struct {
	Success    bool   `json:"success"`
	Query      string `json:"query"`
	SpellFixed string `json:"spell_fixed"`
	IsSafe     bool   `json:"is_safe"`
	AiOverview string `json:"ai_overview"`
	Results    []struct {
		Title        string    `json:"title"`
		URL          string    `json:"url"`
		Description  string    `json:"description"`
		Content      string    `json:"content"`
		SiteName     string    `json:"site_name"`
		SiteLongName string    `json:"site_long_name"`
		Age          time.Time `json:"age"`
		Language     string    `json:"language"`
		IsSafe       bool      `json:"is_safe"`
		Favicon      string    `json:"favicon"`
		Snippets     []string  `json:"snippets"`
		RelatedIndex []struct {
			Title       string `json:"title"`
			URL         string `json:"url"`
			Description string `json:"description"`
			IsSafe      bool   `json:"is_safe"`
		} `json:"related_index,omitempty"`
		Thumbnail string `json:"thumbnail,omitempty"`
	} `json:"results"`
}

WebSearchResponse is the response for the web search api.

type WebSearchSuggestions

type WebSearchSuggestions struct {
	Success     bool     `json:"success"`
	Suggestions []string `json:"suggestions"`
}

WebSearchSuggestions is the response for the web search suggestions api.

Jump to

Keyboard shortcuts

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