Skip to content
Go client for wit.ai HTTP API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml
CODE_OF_CONDUCT.md update legal info (#4) Nov 1, 2018
CONTRIBUTING.md
LICENSE
README.md
apps.go
apps_test.go
entity.go
entity_test.go
export.go
export_test.go Add method for GET /export Jan 27, 2019
go.mod
integration_test.go
message.go update legal info (#4) Nov 1, 2018
message_test.go
samples.go
samples_test.go
witai.go
witai_test.go

README.md

wit.ai

Build Status 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

Parse text

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)
}

Send an audio file

msg, _ := client.Speech(&witai.MessageRequest{
	Speech: &witai.Speech{
		File:        file,
		ContentType: "audio/raw;encoding=unsigned-integer;bits=16;rate=16k;endian=little",
	},
})

Entities

Create:

client.CreateEntity(witai.Entity{
	ID:  "favorite_city",
	Doc: "A city that I like",
})

Get:

client.GetEntity("favorite_city")

Update:

client.UpdateEntity("favorite_city", witai.Entity{
	Doc: "My favorite city",
})

Delete:

client.DeleteEntity("favorite_city")

Entity values

Add:

client.AddEntityValue("favorite_city", witai.EntityValue{
	Value: "HCMC",
	Expressions: ["HoChiMinh", "HCMC"],
})

Delete:

client.DeleteEntityValue("favorite_city", "HCMC")

Value expressions

Add:

client.AddEntityValueExpression("favorite_city", "HCMC", "HoChiMinh")

Delete:

client.DeleteEntityValueExpression("favorite_city", "HCMC", "HoChiMinh")

Training

Validate samples (sentence + entities annotations) to train your app programmatically:

client.ValidateSamples([]witai.Sample{
	Sample{
		Text: "I live in HCMC",
	},
})

Get validate samples:

limit := 10
offset := 0
client.GetSamples(limit, offset)

Export

downloadURL := client.Export()

Testing

Both Unit / Integration tests are executed by TravisCI.

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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.