Documentation ¶
Overview ¶
Package luis is a tools to access Microsoft Translator marketplace API. For more detail, please refer to https://www.microsoft.com/translator/api.aspx
Example ¶
package main import ( "fmt" "os" "github.com/kkdai/luis" "github.com/prometheus/common/log" ) func main() { var API_KEY string var APPID string APPID = os.Getenv("APP_ID") API_KEY = os.Getenv("SUB_KEY") if API_KEY == "" { fmt.Println("Please export your key to environment first, `export SUB_KEY=12234 && export APP_ID=5678`") return } e := luis.NewLuis(API_KEY, APPID) res, err := e.IntelList() if err != nil { log.Error("Error happen on :", err.Err) } fmt.Println("Got response:", string(res)) result := luis.NewIntentListResponse(res) fmt.Println("Luis Intent Ret", result) //Add utterances ex := luis.ExamplePayload{ExampleText: "test", SelectedIntentName: "test2"} res, err = e.AddLabel(ex) //Train it res, err = e.Train() if err != nil { log.Error("Error happen on :", err.Err) } //Predict it, once you have train your models. res, err = e.Predict("test string") if err != nil { log.Error("Error happen on :", err.Err) } fmt.Println("Got response:", string(res)) fmt.Println("Get the best predict result:", luis.GetBestScoreIntent(luis.NewPredictResponse(res))) }
Output:
Index ¶
- Constants
- type ActionChannelsResponse
- type AppInfo
- type Client
- type ErrorResponse
- type ExamplePayload
- type IntentListResponse
- type IntentScore
- type IntentsResultType
- type Luis
- func (l *Luis) ActionChannels() ([]byte, *ErrorResponse)
- func (l *Luis) AddLabel(example ExamplePayload) ([]byte, *ErrorResponse)
- func (l *Luis) GetAppInfo() ([]byte, *ErrorResponse)
- func (l *Luis) GetCurrentProductionVersion() (string, *ErrorResponse)
- func (l *Luis) IntelList() ([]byte, *ErrorResponse)
- func (l *Luis) Predict(utterance string) ([]byte, *ErrorResponse)
- func (l *Luis) Publish(payload PublishPayload) ([]byte, *ErrorResponse)
- func (l *Luis) Train() ([]byte, *ErrorResponse)
- func (l *Luis) Version(versionID string) ([]byte, *ErrorResponse)
- func (l *Luis) Versions() ([]byte, *ErrorResponse)
- type PredictResponse
- type PublishPayload
Examples ¶
Constants ¶
const ( StreamContent string = "application/octet-stream" JsonContent string = "application/json" )
const ( //LuisURL :Basic URL (V1.0) LuisURL string = "https://westus.api.cognitive.microsoft.com/luis/api/v2.0/apps/" //LuisAPIIntents :API Intent List LuisAPIIntents string = "intents" //LuisAPIActionChannels :API Action Channels LuisAPIActionChannels string = "actionChannels" //LuisAPIPredict :API Predict LuisAPIPredict string = "predict" //LuisAPITrain :API Train LuisAPITrain string = "train" //LuisAPIAddExample :API Add Label LuisAPIAddExample string = "example" //LuisAPIPublish :API Publish your application LuisAPIPublish string = "publish" //LuisAPIVersion :API Get application version LuisAPIVersion string = "version" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionChannelsResponse ¶
type ActionChannelsResponse []struct { Name string `json:"Name"` Version int `json:"Version"` SupportURI string `json:"SupportUri"` Actions []struct { Name string `json:"Name"` Parameters []struct { Name string `json:"Name"` DataType string `json:"DataType"` PlaceHolderText string `json:"PlaceHolderText"` Required bool `json:"Required"` } `json:"Parameters"` SupportedAuthenticationTypes []int `json:"SupportedAuthenticationTypes"` } `json:"Actions"` }
ActionChannelsResponse :
type AppInfo ¶
type AppInfo struct { ID string `json:"id"` Name string `json:"name"` Description interface{} `json:"description"` Culture string `json:"culture"` UsageScenario string `json:"usageScenario"` Domain string `json:"domain"` VersionsCount int `json:"versionsCount"` CreatedDateTime time.Time `json:"createdDateTime"` Endpoints struct { PRODUCTION struct { VersionID string `json:"versionId"` IsStaging bool `json:"isStaging"` EndpointURL string `json:"endpointUrl"` AssignedEndpointKey string `json:"assignedEndpointKey"` PublishedDateTime time.Time `json:"publishedDateTime"` } `json:"PRODUCTION"` } `json:"endpoints"` EndpointHitsCount int `json:"endpointHitsCount"` }
AppInfo : Display app detail info
type ErrorResponse ¶
ErrorResponse : Storage all HTTP response include http.response code and error code
type ExamplePayload ¶
type ExamplePayload struct { ExampleText string `json:"text"` SelectedIntentName string `json:"intentName"` EntityLabels []struct { EntityType string `json:"entityName"` StartToken int `json:"startCharIndex"` EndToken int `json:"endCharIndex"` } `json:"entityLabels,omitempty"` }
ExamplePayload :
type IntentListResponse ¶
type IntentListResponse []struct { ID string `json:"id"` Name string `json:"name"` Type string `json:"type"` }
IntentListResponse :
func NewIntentListResponse ¶
func NewIntentListResponse(raw []byte) *IntentListResponse
NewIntentListResponse :
type IntentScore ¶
func GetBestScoreIntent ¶
func GetBestScoreIntent(preResult *PredictResponse) IntentScore
GetBestScoreIntent :Get the best score intent prediction
type IntentsResultType ¶
type Luis ¶
type Luis struct {
// contains filtered or unexported fields
}
Luis :
func (*Luis) ActionChannels ¶
func (l *Luis) ActionChannels() ([]byte, *ErrorResponse)
ActionChannels :get Available Action Channels gets a list of all available action channels for the application
func (*Luis) AddLabel ¶
func (l *Luis) AddLabel(example ExamplePayload) ([]byte, *ErrorResponse)
AddLabel :Add Label Adds a labeled example to the specified application
func (*Luis) GetAppInfo ¶
func (l *Luis) GetAppInfo() ([]byte, *ErrorResponse)
GetAppInfo :Get App detail info and refresh app version id.
func (*Luis) GetCurrentProductionVersion ¶
func (l *Luis) GetCurrentProductionVersion() (string, *ErrorResponse)
func (*Luis) IntelList ¶
func (l *Luis) IntelList() ([]byte, *ErrorResponse)
IntelList :Get All Intent List of this app Retreives information about the intent models.
func (*Luis) Predict ¶
func (l *Luis) Predict(utterance string) ([]byte, *ErrorResponse)
Predict :get Train Model Predictions gets the trained model predictions for the input examples
func (*Luis) Publish ¶
func (l *Luis) Publish(payload PublishPayload) ([]byte, *ErrorResponse)
Publish :Publishes a specific version of the application
func (*Luis) Train ¶
func (l *Luis) Train() ([]byte, *ErrorResponse)
Train :Training Status gets the training status of all models of the specified application
func (*Luis) Version ¶
func (l *Luis) Version(versionID string) ([]byte, *ErrorResponse)
Version :Get application version
func (*Luis) Versions ¶
func (l *Luis) Versions() ([]byte, *ErrorResponse)
Version :Get application version
type PredictResponse ¶
type PredictResponse struct { Query string `json:"query"` TopScoringIntent IntentScore `json:"topScoringIntent"` TotalIntents []IntentScore `json:"intents"` Entities interface{} `json:"entities"` }
PredictResponse :