Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to the Text Generation Endpoint #42

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ See the [examples](./examples) directory.
## Resources

- [Hugging Face](https://huggingface.co/)
- [Inference API JSON Schema](https://huggingface.github.io/text-generation-inference/openapi.json)
- [Model Hub](https://huggingface.co/models)
- [Datasets](https://huggingface.co/datasets)
- [Hugging Face Inference API](https://api-inference.huggingface.co/docs/python/html/index.html) (HF API)
Expand Down
2 changes: 1 addition & 1 deletion audio_classification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

func TestAudioClassificationRequest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion conversational_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/audio_classification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/conversational/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"syscall"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/fill_mask/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/image_classification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/image_segmentation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"golang.org/x/image/font"
"golang.org/x/image/font/basicfont"
"golang.org/x/image/math/fixed"
Expand Down
2 changes: 1 addition & 1 deletion examples/image_to_text/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/object_detection/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"os"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/question_answering/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/sentence_similarity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/speech_recognition/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/summarization/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/table_question_answering/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"text/tabwriter"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const TableRows = 2
Expand Down
2 changes: 1 addition & 1 deletion examples/text_classification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
25 changes: 6 additions & 19 deletions examples/text_generation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package main
import (
"fmt"
"os"
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand All @@ -19,13 +18,9 @@ func init() {
}

func main() {
inputs := []string{
"The answer to life, the universe, and everything is",
"Somebody once told me that the world is gonna roll me",
}
const numReturnSequences = 3
input := "The answer to life, the universe, and everything is"

fmt.Printf("Inputs: [\"%s\"]\n", strings.Join(inputs, `", "`))
fmt.Printf("Input: \"%s\"\n", input)

type ChanRv struct {
resps []*hfapigo.TextGenerationResponse
Expand All @@ -36,9 +31,8 @@ func main() {
fmt.Print("Sending request")
go func() {
resps, err := hfapigo.SendTextGenerationRequest(hfapigo.RecommendedTextGenerationModel, &hfapigo.TextGenerationRequest{
Inputs: inputs,
Parameters: *hfapigo.NewTextGenerationParameters().SetNumReturnSequences(numReturnSequences),
Options: *hfapigo.NewOptions().SetWaitForModel(true),
Input: input,
Options: *hfapigo.NewOptions().SetWaitForModel(true),
})
ch <- ChanRv{resps, err}
}()
Expand All @@ -51,14 +45,7 @@ func main() {
fmt.Println(chrv.err)
return
}
for i := range inputs {
fmt.Printf("\nInput %d results:\n", i)
for _, gt := range chrv.resps[i].GeneratedTexts {
gt = strings.Replace(gt, "\n", " ", -1)
gt = strings.Replace(gt, "\r", " ", -1)
fmt.Println(gt)
}
}
fmt.Printf("Response: %s\n", chrv.resps[0].GeneratedText)
return
default:
fmt.Print(".")
Expand Down
2 changes: 1 addition & 1 deletion examples/text_to_image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/token_classification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/translation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion examples/zeroshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion fill_mask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/Kardbord/hfapigo/v2
module github.com/Kardbord/hfapigo/v3

go 1.17

Expand Down
2 changes: 1 addition & 1 deletion image_classification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hfapigo_test
import (
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

func TestImageClassificationRequest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion image_segmentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hfapigo_test
import (
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

func TestImageSegmentationRequest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion image_to_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

func TestImageToText(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion object_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

func TestObjectDetectionRequest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion question_answering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion sentence_similarity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

const HuggingFaceTokenEnv = "HUGGING_FACE_TOKEN"
Expand Down
2 changes: 1 addition & 1 deletion speech_recognition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
)

func TestSpeechRecognitionRequest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion summarization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion table_question_answering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion text_classification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/Kardbord/hfapigo/v2"
"github.com/Kardbord/hfapigo/v3"
"github.com/google/go-cmp/cmp"
)

Expand Down
Loading
Loading