github.com/hupe1980/go-huggingface@v0.0.15/_examples/text_generation/main.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  
     9  	"github.com/hupe1980/go-huggingface"
    10  )
    11  
    12  func main() {
    13  	ic := huggingface.NewInferenceClient(os.Getenv("HUGGINGFACEHUB_API_TOKEN"))
    14  
    15  	res, err := ic.TextGeneration(context.Background(), &huggingface.TextGenerationRequest{
    16  		Inputs: "The answer to the universe is",
    17  		Model:  "gpt2", // overwrite recommended model
    18  	})
    19  	if err != nil {
    20  		log.Fatal(err)
    21  	}
    22  
    23  	fmt.Println(res[0].GeneratedText)
    24  }