Documentation
¶
Index ¶
- Constants
- Variables
- func GetErrorDetails(err error) map[string]string
- func IsAuthError(err error) bool
- func IsInvalidInputError(err error) bool
- func IsNetworkError(err error) bool
- func IsServerError(err error) bool
- func NewAPIError(statusCode int, message string, cause error) error
- func NewEmptyInputError() error
- func NewInvalidAppIDError(appID string) error
- func NewInvalidInputError(message string) error
- func NewMissingAppIDError() error
- func SimpleQuery(ctx context.Context, appID, input string) (string, error)
- type Client
- type ClientConfig
- type ClientOption
- func WithBaseURL(baseURL string) ClientOption
- func WithBearer(useBearer bool) ClientOption
- func WithDefaultMaxChars(maxChars int) ClientOption
- func WithHTTPClient(client *http.Client) ClientOption
- func WithRetries(retries int) ClientOption
- func WithTimeout(seconds int) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- type LLMResponse
- type QueryParams
Constants ¶
const ( // DefaultBaseURL is the default endpoint URL for Wolfram Alpha LLM API DefaultBaseURL = "https://www.wolframalpha.com/api/v1/llm-api" // DefaultUserAgent is the default User-Agent used for API requests DefaultUserAgent = "go-wolfram-llm/1.0" // DefaultTimeout is the default timeout duration for API requests (in seconds) DefaultTimeout = 30 * time.Second // DefaultMaxRetries is the default number of retries for API request failures DefaultMaxRetries = 3 // DefaultMaxChars is the default value for maximum character count in responses DefaultMaxChars = 6800 )
API-related constants
const Version = "0.1.0"
Version is the library version
Variables ¶
var ( // ErrMissingAppID is returned when AppID is not specified ErrMissingAppID = errors.New("missing AppID") // ErrInvalidAppID is returned when AppID is invalid ErrInvalidAppID = errors.New("invalid AppID") // ErrEmptyInput is returned when the input query is empty ErrEmptyInput = errors.New("input query cannot be empty") // ErrInputTooLong is returned when the input query is too long ErrInputTooLong = errors.New("input query too long") // ErrInvalidMaxChars is returned when the maxchars parameter is invalid ErrInvalidMaxChars = errors.New("invalid maxchars parameter: must be a positive integer") // ErrInvalidInput is returned when the input is invalid (HTTP 501) ErrInvalidInput = errors.New("invalid input: input cannot be interpreted") // ErrMissingInputParam is returned when the input parameter is missing (HTTP 400) ErrMissingInputParam = errors.New("missing input parameter") ErrUnauthorized = errors.New("unauthorized: invalid or missing AppID") // ErrServerError is returned when a server error occurs (HTTP 5xx) ErrServerError = errors.New("server error") // ErrNetworkError is returned when a network error occurs ErrNetworkError = errors.New("network error") // ErrResponseParsing is returned when response parsing fails ErrResponseParsing = errors.New("failed to parse response") )
Predefined errors
Functions ¶
func GetErrorDetails ¶
GetErrorDetails extracts detailed information from an error
func IsAuthError ¶
IsAuthError determines if the error is related to authentication
func IsInvalidInputError ¶
IsInvalidInputError determines if the error is related to invalid input
func IsNetworkError ¶
IsNetworkError determines if the error is related to the network
func IsServerError ¶
IsServerError determines if the error is a server error
func NewAPIError ¶
NewAPIError creates an error for when an API call fails
func NewEmptyInputError ¶
func NewEmptyInputError() error
NewEmptyInputError creates an error for when the input query is empty
func NewInvalidAppIDError ¶
NewInvalidAppIDError creates an error for when AppID is invalid
func NewInvalidInputError ¶
NewInvalidInputError creates an error for when the input query cannot be interpreted
func NewMissingAppIDError ¶
func NewMissingAppIDError() error
NewMissingAppIDError creates an error for when AppID is not specified
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Wolfram Alpha LLM API client
func NewClient ¶
func NewClient(appID string, options ...ClientOption) (*Client, error)
NewClient creates a new Wolfram Alpha LLM API client
func (*Client) QueryWithParams ¶
func (c *Client) QueryWithParams(ctx context.Context, input string, params *QueryParams) (*LLMResponse, error)
QueryWithParams executes a query with parameters
type ClientConfig ¶
type ClientConfig struct {
// AppID is the application ID for Wolfram Alpha API
AppID string
// BaseURL is the base URL for Wolfram Alpha LLM API
BaseURL string
// Timeout is the HTTP request timeout duration
Timeout time.Duration
// MaxRetries is the maximum number of retries for temporary errors
MaxRetries int
// UserAgent is the User-Agent for HTTP requests
UserAgent string
// UseBearer determines whether to use Bearer Token authentication
UseBearer bool
// DefaultMaxChars is the default value for maximum character count in responses
DefaultMaxChars int
// HTTPClient is a custom HTTP client
HTTPClient *http.Client
}
ClientConfig is the configuration for Wolfram Alpha LLM API client
type ClientOption ¶
type ClientOption func(*ClientConfig) error
ClientOption is a function type for client configuration
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL is an option to set custom base URL
func WithBearer ¶
func WithBearer(useBearer bool) ClientOption
WithBearer is an option to set use of Bearer Token authentication
func WithDefaultMaxChars ¶
func WithDefaultMaxChars(maxChars int) ClientOption
WithDefaultMaxChars is an option to set default maximum character count
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient is an option to set custom HTTP client
func WithRetries ¶
func WithRetries(retries int) ClientOption
WithRetries is an option to set maximum number of retries
func WithTimeout ¶
func WithTimeout(seconds int) ClientOption
WithTimeout is an option to set request timeout
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent is an option to set custom User-Agent
type LLMResponse ¶
type LLMResponse struct {
// Result is the result
Result string
}
LLMResponse stores the response from Wolfram Alpha LLM API
type QueryParams ¶
type QueryParams struct {
// Input is the required search query
Input string
// MaxChars is the maximum character count for the response
MaxChars int
// Assumption is the assumption parameter
Assumption string
// IP is the client's IP address
IP string
// LatLong is the latitude and longitude
LatLong string
// Timezone is the timezone
Timezone string
// Location is the location information
Location string
// ScanTimeout is the scan timeout
ScanTimeout float64
// FormatTimeout is the format timeout
FormatTimeout float64
// ParseTimeout is the parse timeout
ParseTimeout float64
// TotalTimeout is the total timeout
TotalTimeout float64
// Units is the unit system ("metric" or "nonmetric")
Units string
// Currency is the currency
Currency string
// CountryCode is the country code
CountryCode string
// LanguageCode is the language code
LanguageCode string
// Width is the width
Width int
// MaxWidth is the maximum width
MaxWidth int
// PlotWidth is the plot width
PlotWidth int
// Mag is the magnification
Mag float64
// ID is the session continuation ID
ID string
}
QueryParams are the parameters for Wolfram Alpha LLM API requests