Go

The official Go SDK documentation for Banana.

Get your Banana API Key

Sign in on the Banana user dashboard to get your key.

Install Banana

Install via go get go get github.com/bananaml/banana-go

Run

package main

import (
	"encoding/json"
	"fmt"
	banana "github.com/bananaml/banana-go"
)

func main() {
	apiKey := "YOUR_API_KEY"
	modelKey := "YOUR_MODEL_KEY"

	// a model input struct specific to the json intake of your model
	type input struct {
		ImageURL string `json:"imageURL"`
	}
	in := input{
		ImageURL: "https://demo-images-banana.s3.us-west-1.amazonaws.com/image2.jpg",
	}

	bytesIn, _ := json.Marshal(in)

	bananaOut, err := banana.Run(apiKey, modelKey, bytesIn)
	if err != nil {
		panic(err)
	}

	// a model output struct specific to the json return of your model
	type output []struct {
		Caption string `json:"caption"`
	}
	out := output{}

	json.Unmarshal(bananaOut.ModelOutputs, &out)

	fmt.Println(out[0].Caption)
}

Output Json

Calls to banana return a json payload with the following structure

{
    "id": "12345678-1234-1234-1234-123456789012",
    "message": "success",
    "created": 1649712752, 
    "apiVersion": "26 Nov 2021", 
    "modelOutputs": [
        {
            # a json specific to your model. In this example, the caption of the image
            "caption": "a baseball player throwing a ball"
        }
    ]
}

Last updated