Documentation ¶
Overview ¶
Captionbot is a simple API wrapper for https://www.captionbot.ai/
Usage
package main import ( "fmt" "os" "github.com/nhatbui/captionbot" ) func main() { bot, err := captionbot.New() if err != nil { fmt.Printf("error instantiating bot %s\n", err) os.Exit(1) } // caption a remote image by provideing a URL imgURL := "http://www.nhatqbui.com/assets/me.jpg" caption, err := bot.URLCaption(imgURL) if err != nil { fmt.Printf("error uploading caption %s\n", err) os.Exit(1) } fmt.Println(caption) // caption a local image by uploading it imgFile := "./sample.jpg" caption, err = bot.UploadCaption(imgFile) if err != nil { fmt.Printf("error uploading caption %s\n", err) os.Exit(1) } fmt.Println(caption) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BaseURL = "https://www.captionbot.ai/api/"
BaseURL is the root path of Caption Bot URL. All requests will be paths starting from here.
Functions ¶
func CreateCaptionTask ¶
CreateCaptionTask is the request that starts a URL caption request on the server. Result will need to be retrieved by a subsequent GET request with the same parameters used here.
func MakeValuesFromState ¶
func MakeValuesFromState(imgURL string, state CaptionBotClientState) url.Values
MakeValuesFromState creates values struct from state struct
Types ¶
type CaptionBot ¶
type CaptionBot struct {
// contains filtered or unexported fields
}
CaptionBot is a struct representing one session with CaptionBot.
func (*CaptionBot) Initialize ¶
func (captionBot *CaptionBot) Initialize() error
Initialize sends request to /init endpoint to retrieve conversationID. This is a session variable used in the state struct.
func (*CaptionBot) URLCaption ¶
func (captionBot *CaptionBot) URLCaption(url string) (string, error)
URLCaption is the entry method for getting caption for image pointed to by URL. Performs a POST request to start the caption task. Then performs a GET request to retrieve the result.
func (*CaptionBot) UploadCaption ¶
func (captionBot *CaptionBot) UploadCaption(fileName string) (string, error)
UploadCaption uploads a file and runs URLCaption on the result
type CaptionBotClientState ¶
type CaptionBotClientState struct {
// contains filtered or unexported fields
}
CaptionBotClientState is a struct to hold "session" state.
- conversationID: given during call to Initialize() Should be used for subsequent requests.
- waterMark: is updated per URL caption response.
(Note: consequences of not maintaining state is unknown.)
type CaptionBotConnection ¶
CaptionBotConnection is an interface for methods for one CaptionBot session.
type CaptionBotRequest ¶
type CaptionBotRequest struct { ConversationID string `json:"conversationID"` UserMessage string `json:"userMessage"` WaterMark string `json:"waterMark"` }
CaptionBotRequest is a struct to hold data for API URL caption requests.