witai

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 9 Imported by: 20

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/v2

Usage

package main

import (
	"os"
	"fmt"

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

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/20200513/
	DefaultVersion = "20200513"
	// 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

type App struct {
	ID      string `json:"id,omitempty"`
	Name    string `json:"name"`
	Lang    string `json:"lang"`
	Private bool   `json:"private"`

	// Timezone is only used when creating/updating an app; it's
	// not available when getting the details of an app.
	Timezone string `json:"timezone,omitempty"`

	CreatedAt Time `json:"created_at,omitempty"`

	WillTrainAt              Time              `json:"will_train_at,omitempty"`
	LastTrainedAt            Time              `json:"last_trained_at,omitempty"`
	LastTrainingDurationSecs int               `json:"last_training_duration_secs,omitempty"`
	TrainingStatus           AppTrainingStatus `json:"training_status,omitempty"`
}

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

type AppTag

type AppTag struct {
	Name string `json:"name,omitempty"`
	Desc string `json:"desc,omitempty"`

	CreatedAt Time `json:"created_at,omitempty"`
	UpdatedAt Time `json:"updated_at,omitempty"`
}

AppTag - https://wit.ai/docs/http/20200513/#get__apps__app_tags__tag_link

type AppTrainingStatus

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 (*Client) AddEntityKeyword

func (c *Client) AddEntityKeyword(entityID string, keyword EntityKeyword) (*Entity, error)

AddEntityKeyword - Add a possible value into the list of values for the keyword entity.

https://wit.ai/docs/http/20200513/#post__entities__entity_keywords_link

func (*Client) AddEntityKeywordSynonym

func (c *Client) AddEntityKeywordSynonym(entityID string, keyword string, synonym string) (*Entity, error)

AddEntityKeywordSynonym - Create a new synonym of the canonical value of the keywords entity.

https://wit.ai/docs/http/20200513/#post__entities__entity_keywords__keyword_synonyms_link

func (*Client) AddTraitValue

func (c *Client) AddTraitValue(traitName string, value string) (*Trait, error)

AddTraitValue - create a new value for a trait.

https://wit.ai/docs/http/20200513/#post__traits__trait_values_link

func (*Client) CreateApp

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

CreateApp - creates new app.

https://wit.ai/docs/http/20200513/#post__apps_link

func (*Client) CreateAppTag

func (c *Client) CreateAppTag(appID string, tag string) (*AppTag, error)

CreateAppTag - Take a snapshot of the current app state, save it as a tag (version) of the app. The name of the tag created will be returned in the response.

https://wit.ai/docs/http/20200513/#post__apps__app_tags_link

func (*Client) CreateEntity

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

CreateEntity - Creates a new entity with the given attributes

https://wit.ai/docs/http/20200513/#post__entities_link

func (*Client) CreateIntent

func (c *Client) CreateIntent(name string) (*Intent, error)

CreateIntent - creates a new intent with the given name.

https://wit.ai/docs/http/20200513/#post__intents_link

func (*Client) CreateTrait

func (c *Client) CreateTrait(name string, values []string) (*Trait, error)

CreateTrait - creates a new trait with the given values.

https://wit.ai/docs/http/20200513/#post__traits_link

func (*Client) DeleteApp

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

DeleteApp - deletes app by ID.

https://wit.ai/docs/http/20200513/#delete__apps__app_link

func (*Client) DeleteAppTag

func (c *Client) DeleteAppTag(appID, tagID string) error

DeleteAppTag - Permanently delete the tag.

https://wit.ai/docs/http/20200513/#delete__apps__app_tags__tag_link

func (*Client) DeleteEntity

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

DeleteEntity - deletes entity by ID or name.

https://wit.ai/docs/http/20200513/#delete__entities__entity_link

func (*Client) DeleteEntityKeyword

func (c *Client) DeleteEntityKeyword(entityID string, keyword string) error

DeleteEntityKeyword - Delete a keyword from the keywords entity.

https://wit.ai/docs/http/20200513/#delete__entities__entity_keywords__keyword_link

func (*Client) DeleteEntityKeywordSynonym

func (c *Client) DeleteEntityKeywordSynonym(entityID string, keyword string, expression string) error

DeleteEntityKeywordSynonym - Delete a synonym of the keyword of the entity.

https://wit.ai/docs/http/20200513/#delete__entities__entity_keywords__keyword_synonyms__synonym_link

func (*Client) DeleteEntityRole

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

DeleteEntityRole - deletes entity role.

https://wit.ai/docs/http/20200513/#delete__entities__entity_role_link

func (*Client) DeleteIntent

func (c *Client) DeleteIntent(name string) error

DeleteIntent - permanently deletes an intent by name.

https://wit.ai/docs/http/20200513/#delete__intents__intent_link

func (*Client) DeleteTrait

func (c *Client) DeleteTrait(name string) error

DeleteTrait - permanently deletes a trait.

https://wit.ai/docs/http/20200513/#delete__traits__trait_link

func (*Client) DeleteTraitValue

func (c *Client) DeleteTraitValue(traitName string, value string) error

DeleteTraitValue - permanently deletes the trait value.

https://wit.ai/docs/http/20200513/#delete__traits__trait_values__value_link

func (*Client) DeleteUtterances

func (c *Client) DeleteUtterances(texts []string) (*TrainingResponse, error)

DeleteUtterances - Delete validated utterances from your app.

https://wit.ai/docs/http/20200513/#delete__utterances_link

func (*Client) Detect

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

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

func (*Client) Export

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

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

func (*Client) GetApp

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

GetApp - Returns an object representation of the specified app.

https://wit.ai/docs/http/20200513/#get__apps__app_link

func (*Client) GetAppTag

func (c *Client) GetAppTag(appID, tagID string) (*AppTag, error)

GetAppTag - returns the detail of the specified tag.

https://wit.ai/docs/http/20200513/#get__apps__app_tags__tag_link

func (*Client) GetAppTags

func (c *Client) GetAppTags(appID string) ([][]AppTag, error)

GetAppTags - Returns an array of all tag groups for an app. Within a group, all tags point to the same app state (as a result of moving tags).

https://wit.ai/docs/http/20200513/#get__apps__app_tags_link

func (*Client) GetApps

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/20200513/#get__apps_link

func (*Client) GetEntities

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

GetEntities - returns list of entities.

https://wit.ai/docs/http/20200513/#get__entities_link

func (*Client) GetEntity

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

GetEntity - returns entity by ID or name.

https://wit.ai/docs/http/20200513/#get__entities__entity_link

func (*Client) GetIntent

func (c *Client) GetIntent(name string) (*Intent, error)

GetIntent - returns intent by name.

https://wit.ai/docs/http/20200513/#get__intents__intent_link

func (*Client) GetIntents

func (c *Client) GetIntents() ([]Intent, error)

GetIntents - returns the list of intents.

https://wit.ai/docs/http/20200513/#get__intents_link

func (*Client) GetTrait

func (c *Client) GetTrait(name string) (*Trait, error)

GetTrait - returns all available information about a trait.

https://wit.ai/docs/http/20200513/#get__traits__trait_link

func (*Client) GetTraits

func (c *Client) GetTraits() ([]Trait, error)

GetTraits - returns a list of traits.

https://wit.ai/docs/http/20200513/#get__traits_link

func (*Client) GetUtterances

func (c *Client) GetUtterances(limit int, offset int) ([]Utterance, error)

GetUtterances - Returns an array of utterances.

https://wit.ai/docs/http/20200513/#get__utterances_link

func (*Client) MoveAppTag

func (c *Client) MoveAppTag(appID, tagID string, to string, updated *AppTag) (*MovedAppTag, error)

MoveAppTag - move the tag to point to another tag.

https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link

func (*Client) Parse

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

Parse - parses text and returns entities

func (*Client) SetHTTPClient

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

SetHTTPClient allows to use your custom http.Client

func (*Client) Speech

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

Speech - sends audio file for parsing

func (*Client) TrainUtterances

func (c *Client) TrainUtterances(trainings []Training) (*TrainingResponse, error)

TrainUtterances - Add utterances (sentence + entities annotations) to train your app programmatically.

https://wit.ai/docs/http/20200513/#post__utterances_link

func (*Client) UpdateApp

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

UpdateApp - Updates an app.

https://wit.ai/docs/http/20200513/#put__apps__app_link

func (*Client) UpdateAppTag

func (c *Client) UpdateAppTag(appID, tagID string, updated AppTag) (*AppTag, error)

UpdateAppTag - Update the tag's name or description

https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link

func (*Client) UpdateEntity

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

UpdateEntity - Updates an entity by ID or name.

https://wit.ai/docs/http/20200513/#put__entities__entity_link

type CreatedApp

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

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

type Entity

type Entity struct {
	ID       string          `json:"id"`
	Name     string          `json:"name"`
	Lookups  []string        `json:"lookups,omitempty"`
	Roles    []string        `json:"roles,omitempty"`
	Keywords []EntityKeyword `json:"keywords,omitempty"`
}

Entity represents a wit-ai Entity.

https://wit.ai/docs/http/20200513/#post__entities_link

type EntityKeyword

type EntityKeyword struct {
	Keyword  string   `json:"keyword"`
	Synonyms []string `json:"synonyms"`
}

EntityKeyword is a keyword lookup for an Entity.

https://wit.ai/docs/http/20200513/#post__entities__entity_keywords_link

type Intent

type Intent struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	Entities []Entity `json:"entities,omitempty"`
}

Intent - represents a wit-ai intent.

https://wit.ai/docs/http/20200513/#get__intents_link

type Locale

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

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

type Locales

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

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

type MessageContext

type MessageContext struct {
	ReferenceTime 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

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

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

type MessageEntity

type MessageEntity struct {
	ID         string                 `json:"id"`
	Name       string                 `json:"name"`
	Role       string                 `json:"role"`
	Start      int                    `json:"start"`
	End        int                    `json:"end"`
	Body       string                 `json:"body"`
	Value      string                 `json:"value"`
	Confidence float64                `json:"confidence"`
	Entities   []MessageEntity        `json:"entities"`
	Extra      map[string]interface{} `json:"-"`
}

MessageEntity - https://wit.ai/docs/http/20200513/#get__message_link

type MessageIntent

type MessageIntent struct {
	ID         string  `json:"id"`
	Name       string  `json:"name"`
	Confidence float64 `json:"confidence"`
}

MessageIntent - https://wit.ai/docs/http/20200513/#get__message_link

type MessageRequest

type MessageRequest struct {
	Query   string          `json:"q"`
	Tag     string          `json:"tag"`
	N       int             `json:"n"`
	Context *MessageContext `json:"context"`
	Speech  *Speech         `json:"-"`
}

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

type MessageResponse

type MessageResponse struct {
	ID       string                     `json:"msg_id"`
	Text     string                     `json:"text"`
	Intents  []MessageIntent            `json:"intents"`
	Entities map[string][]MessageEntity `json:"entities"`
	Traits   map[string][]MessageTrait  `json:"traits"`
}

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

type MessageTrait

type MessageTrait struct {
	ID         string                 `json:"id"`
	Value      string                 `json:"value"`
	Confidence float64                `json:"confidence"`
	Extra      map[string]interface{} `json:"-"`
}

MessageTrait - https://wit.ai/docs/http/20200513/#get__message_link

type MovedAppTag

type MovedAppTag struct {
	Tag     string `json:"tag"`
	Desc    string `json:"desc"`
	MovedTo string `json:"moved_to"`
}

type Speech

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

type Time struct {
	time.Time
}

Time - Custom type to encapsulated a time.Time

func (*Time) UnmarshalJSON

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

UnmarshalJSON - Our unmarshal function for our custom type

type Training

type Training struct {
	Text     string           `json:"text"`
	Intent   string           `json:"intent,omitempty"`
	Entities []TrainingEntity `json:"entities"`
	Traits   []TrainingTrait  `json:"traits"`
}

TrainingResponse - https://wit.ai/docs/http/20200513/#post__utterances_link

type TrainingEntity

type TrainingEntity struct {
	Entity   string           `json:"entity"`
	Start    int              `json:"start"`
	End      int              `json:"end"`
	Body     string           `json:"body"`
	Entities []TrainingEntity `json:"entities"`
}

TrainingResponse - https://wit.ai/docs/http/20200513/#post__utterances_link

type TrainingResponse

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

TrainingResponse - https://wit.ai/docs/http/20200513/#post__utterances_link

type TrainingTrait

type TrainingTrait struct {
	Trait string `json:"trait"`
	Value string `json:"value"`
}

TrainingResponse - https://wit.ai/docs/http/20200513/#post__utterances_link

type Trait

type Trait struct {
	ID     string       `json:"id"`
	Name   string       `json:"name"`
	Values []TraitValue `json:"values"`
}

Trait - represents a wit-ai trait.

https://wit.ai/docs/http/20200513/#post__traits_link

type TraitValue

type TraitValue struct {
	ID    string `json:"id"`
	Value string `json:"value"`
}

TraitValue - represents the value of a Trait.

https://wit.ai/docs/http/20200513/#get__traits__trait_link

type UpdateAppTagRequest

type UpdateAppTagRequest struct {
	Tag    string `json:"tag,omitempty"`
	Desc   string `json:"desc,omitempty"`
	MoveTo string `json:"move_to,omitempty"`
}

UpdateAppTagRequest - https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link

type UpdateAppTagResponse

type UpdateAppTagResponse struct {
	Tag     string `json:"tag,omitempty"`
	Desc    string `json:"desc,omitempty"`
	MovedTo string `json:"moved_to,omitempty"`
}

UpdateAppTagResponse - https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link

type Utterance

type Utterance struct {
	Text     string            `json:"text"`
	Intent   UtteranceIntent   `json:"intent"`
	Entities []UtteranceEntity `json:"entities"`
	Traits   []UtteranceTrait  `json:"traits"`
}

Utterance - https://wit.ai/docs/http/20200513/#get__utterances_link

type UtteranceEntity

type UtteranceEntity struct {
	ID       string            `json:"id"`
	Name     string            `json:"name"`
	Role     string            `json:"role"`
	Start    int               `json:"start"`
	End      int               `json:"end"`
	Body     string            `json:"body"`
	Entities []UtteranceEntity `json:"entities"`
}

UtteranceEntity - https://wit.ai/docs/http/20200513/#get__utterances_link

type UtteranceIntent

type UtteranceIntent struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

UtteranceIntent - https://wit.ai/docs/http/20200513/#get__utterances_link

type UtteranceTrait

type UtteranceTrait struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

UtteranceTrait - https://wit.ai/docs/http/20200513/#get__utterances_link

Jump to

Keyboard shortcuts

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