Go client for wit.ai HTTP API

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.

Owner
Wit.ai
Natural Language for everyone
Wit.ai
Comments
  • BREAKING: Bump API version to 20200513

    BREAKING: Bump API version to 20200513

    Description

    This PR updates the library to support wit.ai's latest API version. See #17.

    Pull Requests

    Thanks for proposing a pull request.

    To help us review the request, please complete the following:

    • [x] sign contributor license agreement: https://developers.facebook.com/opensource/cla
    • [x] submit against our master.
    • [x] describe the change (for example, what happens before the change, and after the change)
  • API Versioning not working

    API Versioning not working

    Since wit.ai v2 the wit-go is broken. I thought NewClientWithVersion(token, DefaultVersion) would prevent this, as it calls the API with API versioning. But the API may not send an old-fashioned result back.

    It will not work with v2, but DefaultVersion = "20170307" don't ensure, that this version is used.

    I think it is not an issue of wit-go, but with the API. But to workaround this issue, it is needed to update wit-go to the latest version of the API.

  • Failed to validate sample at index 0. Start must be less than end

    Failed to validate sample at index 0. Start must be less than end

    While using the ValidateSamples method with the sample code shown in the docs : https://wit.ai/docs/http/20170307#post__samples_link

    [{
            "text": "I want to fly to sfo",
            "entities": [
              {
                "entity": "intent",
                "value": "flight_request"
              },
              {
                "entity": "wit$location",
                "start": 17,
                "end": 20,
                "value": "sfo"
              }
            ]
          }]
    

    I'm getting error : unable to make a request. error: Failed to validate sample at index 0. Start must be less than end.

    I also slightly altered your integration test to reproduce the same error. I added below code to the TestIntegrationSamples test :

    // samples test
    	_, validateErr := c.ValidateSamples([]Sample{
    		{
    			Text: "I want to fly SFO",
    			Entities: []SampleEntity{
    				{
    					Entity: "intent",
    					Value:  "flight_request",
    				},
    				{
    					Entity: "wit$location",
    					Value:  "SFO",
    					Start:  17,
    					End:    20,
    				},
    			},
    		},
    	})
    

    The added lines were just to make the test match the sample curl command in the docs : https://wit.ai/docs/http/20170307#post__samples_link

    And as suspected the integration test now fails with :

    === RUN   TestIntegrationSamples
    --- FAIL: TestIntegrationSamples (5.53s)
        integration_test.go:197: expected nil error, got unable to make a request. error: Failed to validate sample at index 0. Start must be less than end.
    

    I believe this is because the struct def has int values for the start and end fields, but in this example where the intent doesn't need the text selection to be called out (like when you have a trait lookup strategy) so there is no value given for start and end, they are give the zero value for the type, which is 0.

    The problem is the api receives :

    [
      {
        "text": "I want to fly to sfo",
        "entities": [
          {
            "entity": "intent",
            "value": "flight_request",
            "start": 0,
            "end": 0,
            "role": "",
            "subentities": null,
          },
          {
            "entity": "wit$location",
            "value": "SFO",
            "start": 17,
            "end": 20,
            "role": "",
            "subentities": null,
          }
        ]
      }
    ]
    

    and it responds with a 400 :

    {
      "error": "Failed to validate sample at index 0. Start must be less than end.",
      "code": "bad-request"
    }
    

    If I hit the api outside of the library and replace the values of start and end with null or omit them completely then I get back a 200 and it works as expected.

    Maybe I'm missing something here? I would really appreciate some help here. Thanks!

  • V2 is incorrectly packaged for Go modules

    V2 is incorrectly packaged for Go modules

    The latest release of this package is a major version (2.0.0) and thus requires a /v2 suffix on the module path per the Go modules docs. It is currently impossible to install the v2.0.0 release of this package via go get because of invalid packaging.

  • Support for API version 20200513

    Support for API version 20200513

    The latest version of the API response contract doesn't seem to match the current struct definition. Are there any plans to support this, maybe in v2 (since this is definitely breaking)? Is it fine if I create a PR for this?

  • QueryEscape dont work with wit.ai api

    QueryEscape dont work with wit.ai api

    Hey,

    I dont know if this issue should be reported here or in the main wit.ai repo.

    But with the golang client when i try to delete a value with a space in it for an intent e.g

    wit.DeleteEntityValue("intent", "Au revoir") The value is not deleted on wit.ai because of this : url.QueryEscape(value)

    Standard QueryEscape call encodes a space with a "+" character.

    Also this curl command dont work curl -XDELETE 'https://api.wit.ai/entities/intent/values/Au+revoir?v=20170307' But this one does curl -XDELETE 'https://api.wit.ai/entities/intent/values/Au%20revoir?v=20170307'

  • App creation should return correct struct instead of an App

    App creation should return correct struct instead of an App

    According the wit.ai doc [1] when we create an app the response as the following structure { "access_token" : "NEW_ACCESS_TOKEN", "app_id" : "NEW_APP_ID" }

    Then instead of returning an empty app the function CreateApp should return this structure instead of an empty App

    [1] https://wit.ai/docs/http/20170307#post__apps_link

  • Specify a specific http.Client

    Specify a specific http.Client

    I'd like to use this library on google appengine. Though Appengine doesn't allow outbound http request [1], thus we should be able to pass a specific http.Client

    [1] https://cloud.google.com/appengine/docs/standard/go/issue-requests

  • update changelog

    update changelog

    Pull Requests

    Thanks for proposing a pull request.

    To help us review the request, please complete the following:

    • [x] sign contributor license agreement: https://developers.facebook.com/opensource/cla
    • [x] submit against our master.
    • [x] describe the change (for example, what happens before the change, and after the change)
  • #9: Replace QueryEscape with PathEscape

    #9: Replace QueryEscape with PathEscape

    Example value: Ho Chi Minh City. Previous code would escape as Ho+Chi+Minh+City and requests will fail. The new code will escape as Ho%20Chi%20Minh%20City and will work.

  • I don't know how to parse Entities from MessageResponse ?

    I don't know how to parse Entities from MessageResponse ?

    Hello,

    Sorry for a basic question but I wasted 5 days for that problem

    // communicate with AI service
    	result, err := witClient.Parse(&witai.MessageRequest{
    		Query: textMessage,
    	})
    
    	if err != nil { // handle error
    
    	}
    	// we have `result` (witai.MessageResponse) here
    	data := []byte(result.Entities) // cannot continue because error convert from interface{} to []byte
    

    I cannot continue because error convert from interface{} to []byte.

    I want to extract entities key to an array and entities content to an another.

    Hope you can guide me how to extract that.

    Thanks in advanced !

Clusterpedia-client - clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Jan 7, 2022
Client-go - Clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Dec 5, 2022
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Kinesumer is a Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Jan 5, 2023
⚡️ SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang)
⚡️ SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang)

Gosip - SharePoint authentication, HTTP client & fluent API wrapper for Go (Golang) Main features Unattended authentication using different strategies

Jan 2, 2023
Nutanix-client-go - Go client for the Nutanix Prism V3 API

nutanix-client-go This repository contains portions of the Nutanix API client code in nutanix/terraform-provider-nutanix. It has been extracted to red

Jan 6, 2022
Go library for accessing the MyAnimeList API: http://myanimelist.net/modules.php?go=api

go-myanimelist go-myanimelist is a Go client library for accessing the MyAnimeList API. Project Status The MyAnimeList API has been stable for years a

Sep 28, 2022
Go client for the YNAB API. Unofficial. It covers 100% of the resources made available by the YNAB API.

YNAB API Go Library This is an UNOFFICIAL Go client for the YNAB API. It covers 100% of the resources made available by the YNAB API. Installation go

Oct 6, 2022
An API client for the Notion API implemented in Golang

An API client for the Notion API implemented in Golang

Dec 30, 2022
A Wrapper Client for Google Spreadsheet API (Sheets API)

Senmai A Wrapper Client for Google Spreadsheet API (Sheets API) PREPARATION Service Account and Key File Create a service account on Google Cloud Plat

Nov 5, 2021
Simple-Weather-API - Simple weather api app created using golang and Open Weather API key
Simple-Weather-API - Simple weather api app created using golang and Open Weather API key

Simple Weather API Simple weather api app created using golang and Open Weather

Feb 6, 2022
Client for the cloud-iso-client

cloud-iso-client Client for the cloud-iso-client. Register an API token Before using this client library, you need to register an API token under your

Dec 6, 2021
Aoe4-client - Client library for aoe4 leaderboards etc

AOE4 Client Overview This is a go client used to query AOE4 data from either the

Jan 18, 2022
Balabola-go-client - GO client for Yandex balabola service

Balabola GO Client GO client for Yandex balabola service Yandex warning The neur

Jan 29, 2022
Client-server-golang-sqs - Client Server with SQS and golang

Client Server with SQS and golang Multi-threaded client-server demo with Go What

Feb 14, 2022
Go library for http://www.brewerydb.com/ API

brewerydb brewerydb is a Go library for accessing the BreweryDB API usage import "github.com/naegelejd/brewerydb" Construct a new Client using your Br

Sep 27, 2022
API-HTTP service for wav-file synthesis based on sound library (morphemes)

Сервис для генерации аудио-файлов по заданной последовательности звуков из библиотеки. Предоставляет HTTP-API для передачи последовательности для гене

Jan 9, 2022
Go Client Library for Amazon Product Advertising API

go-amazon-product-advertising-api Go Client Library for Amazon Product Advertising API How to Use go get -u github.com/ngs/go-amazon-product-advertisi

Sep 27, 2022
A Go client library for the Twitter 1.1 API

Anaconda Anaconda is a simple, transparent Go package for accessing version 1.1 of the Twitter API. Successful API queries return native Go structs th

Jan 1, 2023
Go client library for interacting with Coinpaprika's API

Coinpaprika API Go Client Usage This library provides convenient way to use coinpaprika.com API in Go. Coinpaprika delivers full market data to the wo

Dec 8, 2022