witai

package module
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: MIT Imports: 9 Imported by: 9

README

wit.ai

GoDoc Go Report Card

This repository is community-maintained. We gladly accept pull requests. Please see the Wit HTTP Reference for all supported endpoints.

Go client for wit.ai HTTP API.

Install

go get -u github.com/wit-ai/wit-go

Usage

package main

import (
	"os"
	"fmt"

	witai "github.com/wit-ai/wit-go"
)

func main() {
	client := witai.NewClient(os.Getenv("WIT_AI_TOKEN"))
	// Use client.SetHTTPClient() to set custom http.Client

	msg, _ := client.Parse(&witai.MessageRequest{
		Query: "hello",
	})
	fmt.Printf("%v", msg)
}

Testing

Both Unit / Integration tests are executed by Github Actions.

Unit tests

go test -race -v

Integration tests

Integration tests are connecting to real Wit.ai API, so you need to provide a valid token:

export WITAI_INTEGRATION_TOKEN=your_secret_token_here
go test -v -tags=integration

License

The license for wit-go can be found in LICENSE file in the root directory of this source tree.

Documentation

Index

Constants

View Source
const (
	// DefaultVersion - https://wit.ai/docs/http/20170307
	DefaultVersion = "20170307"
	// WitTimeFormat - the custom format of the timestamp sent by the api
	WitTimeFormat = "2006-01-02T15:04:05Z0700"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type App added in v0.0.2

type App struct {
	Name    string `json:"name"`
	Lang    string `json:"lang"`
	Private bool   `json:"private"`
	// Description presents when we get an app
	Description string `json:"description,omitempty"`
	// Use Desc when create an app
	Desc string `json:"desc,omitempty"`
	// ID presents when we get an app
	ID string `json:"id,omitempty"`
	// AppID presents when we create an app
	AppID     string `json:"app_id,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
	Timezone  string `json:"timezone,omitempty"`
	// Training information
	LastTrainingDurationSecs int               `json:"last_training_duration_secs,omitempty"`
	WillTrainAt              Time              `json:"will_train_at,omitempty"`
	LastTrainedAt            Time              `json:"last_trained_at,omitempty"`
	TrainingStatus           AppTrainingStatus `json:"training_status,omitempty"`
}

App - https://wit.ai/docs/http/20170307#get__apps_link

type AppTrainingStatus added in v1.0.4

type AppTrainingStatus string

AppTrainingStatus - Represents the status of an app

const (
	// Done status
	Done AppTrainingStatus = "done"
	// Scheduled status
	Scheduled AppTrainingStatus = "scheduled"
	// Ongoing status
	Ongoing AppTrainingStatus = "ongoing"
)

type Client

type Client struct {
	APIBase string
	Token   string
	Version string
	// contains filtered or unexported fields
}

Client - Wit.ai client type

func NewClient

func NewClient(token string) *Client

NewClient - returns Wit.ai client for default API version

func NewClientWithVersion

func NewClientWithVersion(token, version string) *Client

NewClientWithVersion - returns Wit.ai client for specified API version

func (*Client) AddEntityValue added in v0.0.2

func (c *Client) AddEntityValue(entityID string, value EntityValue) (*Entity, error)

AddEntityValue - Add a possible value into the list of values for the keyword entity. https://wit.ai/docs/http/20170307#post__entities__entity_id_values_link

func (*Client) AddEntityValueExpression added in v0.0.2

func (c *Client) AddEntityValueExpression(entityID string, value string, expression string) (*Entity, error)

AddEntityValueExpression - Create a new expression of the canonical value of the keyword entity. https://wit.ai/docs/http/20170307#post__entities__entity_id_values__value_id_expressions_link

func (*Client) CreateApp added in v0.0.2

func (c *Client) CreateApp(app App) (*CreatedApp, error)

CreateApp - creates new app. https://wit.ai/docs/http/20170307#post__apps_link

func (*Client) CreateEntity added in v0.0.2

func (c *Client) CreateEntity(entity Entity) (*Entity, error)

CreateEntity - Creates a new entity with the given attributes. https://wit.ai/docs/http/20170307#post__entities_link

func (*Client) DeleteApp added in v0.0.2

func (c *Client) DeleteApp(id string) error

DeleteApp - deletes app by ID. https://wit.ai/docs/http/20170307#delete__apps__app_id_link

func (*Client) DeleteEntity added in v0.0.2

func (c *Client) DeleteEntity(id string) error

DeleteEntity - deletes entity by ID. https://wit.ai/docs/http/20170307#delete__entities__entity_id_link

func (*Client) DeleteEntityRole added in v0.0.2

func (c *Client) DeleteEntityRole(entityID string, role string) error

DeleteEntityRole - deletes entity role. https://wit.ai/docs/http/20170307#delete__entities__entity_id_role_id_link

func (*Client) DeleteEntityValue added in v0.0.2

func (c *Client) DeleteEntityValue(entityID string, value string) error

DeleteEntityValue - Delete a canonical value from the entity. https://wit.ai/docs/http/20170307#delete__entities__entity_id_values_link

func (*Client) DeleteEntityValueExpression added in v0.0.2

func (c *Client) DeleteEntityValueExpression(entityID string, value string, expression string) error

DeleteEntityValueExpression - Delete an expression of the canonical value of the entity. https://wit.ai/docs/http/20170307#delete__entities__entity_id_values__value_id_expressions_link

func (*Client) DeleteSamples added in v0.0.3

func (c *Client) DeleteSamples(samples []Sample) (*ValidateSampleResponse, error)

DeleteSamples - Delete validated samples from your app. https://wit.ai/docs/http/20170307#delete__samples_link Only text property is required

func (*Client) Detect added in v1.0.7

func (c *Client) Detect(text string) (*Locales, error)

Detect - returns the detected languages from query - https://wit.ai/docs/http/20170307#get__language_link

func (*Client) Export added in v1.0.0

func (c *Client) Export() (string, error)

Export - Returns download URI. https://wit.ai/docs/http/20170307#get__export_link

func (*Client) GetApp added in v0.0.2

func (c *Client) GetApp(id string) (*App, error)

GetApp - returns map by ID. https://wit.ai/docs/http/20170307#get__apps__app_id_link

func (*Client) GetApps added in v0.0.2

func (c *Client) GetApps(limit int, offset int) ([]App, error)

GetApps - Returns an array of all apps that you own. https://wit.ai/docs/http/20170307#get__apps_link

func (*Client) GetEntities added in v0.0.2

func (c *Client) GetEntities() ([]string, error)

GetEntities - returns list of entities. https://wit.ai/docs/http/20170307#get__entities_link

func (*Client) GetEntity added in v0.0.2

func (c *Client) GetEntity(id string) (*Entity, error)

GetEntity - returns entity by ID. https://wit.ai/docs/http/20170307#get__entities__entity_id_link

func (*Client) GetSamples added in v0.0.3

func (c *Client) GetSamples(limit int, offset int) ([]Sample, error)

GetSamples - Returns an array of samples. https://wit.ai/docs/http/20170307#get__samples_link

func (*Client) Parse added in v0.0.2

func (c *Client) Parse(req *MessageRequest) (*MessageResponse, error)

Parse - parses text and returns entities

func (*Client) SetHTTPClient added in v1.0.0

func (c *Client) SetHTTPClient(httpClient *http.Client)

SetHTTPClient allows to use your custom http.Client

func (*Client) Speech added in v0.0.2

func (c *Client) Speech(req *MessageRequest) (*MessageResponse, error)

Speech - sends audio file for parsing

func (*Client) UpdateApp added in v0.0.2

func (c *Client) UpdateApp(id string, app App) (*App, error)

UpdateApp - Updates an app. https://wit.ai/docs/http/20170307#put__apps__app_id_link

func (*Client) UpdateEntity added in v0.0.2

func (c *Client) UpdateEntity(id string, entity Entity) error

UpdateEntity - Updates an entity. https://wit.ai/docs/http/20170307#put__entities__entity_id_link

func (*Client) ValidateSamples added in v0.0.3

func (c *Client) ValidateSamples(samples []Sample) (*ValidateSampleResponse, error)

ValidateSamples - Validate samples (sentence + entities annotations) to train your app programmatically. https://wit.ai/docs/http/20170307#post__samples_link

type CreatedApp added in v1.0.1

type CreatedApp struct {
	AccessToken string `json:"access_token"`
	AppID       string `json:"app_id"`
}

CreatedApp - https://wit.ai/docs/http/20170307#post__apps_link

type Entity added in v0.0.2

type Entity struct {
	ID      string        `json:"id"`
	Doc     string        `json:"doc"`
	Name    string        `json:"name,omitempty"`
	Lang    string        `json:"lang,omitempty"`
	Builtin bool          `json:"builtin,omitempty"`
	Lookups []string      `json:"lookups,omitempty"`
	Values  []EntityValue `json:"values,omitempty"`
}

Entity - https://wit.ai/docs/http/20170307#post__entities_link

type EntityValue added in v0.0.2

type EntityValue struct {
	Value       string   `json:"value"`
	Expressions []string `json:"expressions"`
	MetaData    string   `json:"metadata"`
}

EntityValue - https://wit.ai/docs/http/20170307#get__entities__entity_id_link

type Locale added in v1.0.7

type Locale struct {
	Locale     string  `json:"locale"`
	Confidence float64 `json:"confidence"`
}

Locale - https://wit.ai/docs/http/20170307#get__language_link

type Locales added in v1.0.7

type Locales struct {
	DetectedLocales []Locale `json:"detected_locales"`
}

Locales - https://wit.ai/docs/http/20170307#get__language_link

type MessageContext added in v0.0.2

type MessageContext struct {
	TeferenceTime string        `json:"reference_time"` // "2014-10-30T12:18:45-07:00"
	Timezone      string        `json:"timezone"`
	Locale        string        `json:"locale"`
	Coords        MessageCoords `json:"coords"`
}

MessageContext - https://wit.ai/docs/http/20170307#context_link

type MessageCoords added in v0.0.2

type MessageCoords struct {
	Lat  float32 `json:"lat"`
	Long float32 `json:"long"`
}

MessageCoords - https://wit.ai/docs/http/20170307#context_link

type MessageRequest added in v0.0.2

type MessageRequest struct {
	Query    string          `json:"q"`
	MsgID    string          `json:"msg_id"`
	N        int             `json:"n"`
	ThreadID string          `json:"thread_id"`
	Context  *MessageContext `json:"context"`
	Speech   *Speech         `json:"-"`
}

MessageRequest - https://wit.ai/docs/http/20170307#get__message_link

type MessageResponse added in v0.0.2

type MessageResponse struct {
	ID       string                 `json:"msg_id"`
	Text     string                 `json:"_text"`
	Entities map[string]interface{} `json:"entities"`
}

MessageResponse - https://wit.ai/docs/http/20170307#get__message_link

type Sample added in v0.0.3

type Sample struct {
	Text     string         `json:"text"`
	Entities []SampleEntity `json:"entities"`
}

Sample - https://wit.ai/docs/http/20170307#get__samples_link

type SampleEntity added in v0.0.3

type SampleEntity struct {
	Entity       string         `json:"entity"`
	Value        string         `json:"value"`
	Role         string         `json:"role"`
	Start        int            `json:"start"`
	End          int            `json:"end"`
	Subentitites []SampleEntity `json:"subentities"`
}

SampleEntity - https://wit.ai/docs/http/20170307#get__samples_link

type Speech added in v0.0.2

type Speech struct {
	File        io.Reader `json:"file"`
	ContentType string    `json:"content_type"` // Example: audio/raw;encoding=unsigned-integer;bits=16;rate=8000;endian=big
}

Speech - https://wit.ai/docs/http/20170307#post__speech_link

type Time added in v1.0.8

type Time struct {
	time.Time
}

Time - Custom type to encapsulated a time.Time

func (*Time) UnmarshalJSON added in v1.0.8

func (witTime *Time) UnmarshalJSON(input []byte) error

UnmarshalJSON - Our unmarshal function for our custom type

type ValidateSampleResponse added in v0.0.3

type ValidateSampleResponse struct {
	Sent bool `json:"sent"`
	N    int  `json:"n"`
}

ValidateSampleResponse - https://wit.ai/docs/http/20170307#post__samples_link

Jump to

Keyboard shortcuts

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