Skip to content

Commit

Permalink
September '24 Maintenance (#45)
Browse files Browse the repository at this point in the history
* Fail unit tests early if no API key is detected

* Updated text-to-image model to a mirror of the old model

* Removed retries in models that don't have a wait-for-model option as they were causing rate limits
  • Loading branch information
Kardbord authored Oct 1, 2024
1 parent 8d9e252 commit 62b0c96
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 51 deletions.
12 changes: 1 addition & 11 deletions audio_classification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ package hfapigo_test

import (
"testing"
"time"

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

func TestAudioClassificationRequest(t *testing.T) {
const retries = 10

acResps := []*hfapigo.AudioClassificationResponse{}
var err error
for i := 0; i < retries; i++ {
acResps, err = hfapigo.SendAudioClassificationRequest(hfapigo.RecommendedAudioClassificationModel, TestFilesDir+"/sample.flac")
if err == nil {
break
} else {
time.Sleep(time.Second * 5)
}
}
acResps, err = hfapigo.SendAudioClassificationRequest(hfapigo.RecommendedAudioClassificationModel, TestFilesDir+"/sample.flac")
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 1 addition & 11 deletions image_to_text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@ package hfapigo_test

import (
"testing"
"time"

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

func TestImageToText(t *testing.T) {
const retries = 10

resps := []*hfapigo.ImageToTextResponse{}
var err error
for i := 0; i < retries; i++ {
resps, err = hfapigo.SendImageToTextRequest(hfapigo.RecommendedImageToTextModel, TestFilesDir+"/test-image.png")
if err == nil {
break
} else {
time.Sleep(time.Second * 5)
}
}

resps, err = hfapigo.SendImageToTextRequest(hfapigo.RecommendedImageToTextModel, TestFilesDir+"/test-image.png")
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 1 addition & 11 deletions object_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ package hfapigo_test

import (
"testing"
"time"

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

func TestObjectDetectionRequest(t *testing.T) {
const retries = 10

resps := []*hfapigo.ObjectDetectionResponse{}
var err error
for i := 0; i < retries; i++ {
resps, err = hfapigo.SendObjectDetectionRequest(hfapigo.RecommendedObjectDetectionModel, TestFilesDir+"/test-image.png")
if err == nil {
break
} else {
time.Sleep(time.Second * 5)
}
}
resps, err = hfapigo.SendObjectDetectionRequest(hfapigo.RecommendedObjectDetectionModel, TestFilesDir+"/test-image.png")
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 3 additions & 6 deletions setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ func init() {
}

func TestMain(m *testing.M) {
shouldWarn := hfapigo.APIKey() == ""
if shouldWarn {
fmt.Printf("%s not found in env, tests may fail due to rate limiting.\n", HuggingFaceTokenEnv)
if hfapigo.APIKey() == "" {
fmt.Fprintf(os.Stderr, "%s not set, tests will fail due to rate limiting.", HuggingFaceTokenEnv)
os.Exit(1)
}
m.Run()
if shouldWarn {
fmt.Printf("%s not found in env, tests may fail due to rate limiting.\n", HuggingFaceTokenEnv)
}
}
12 changes: 1 addition & 11 deletions speech_recognition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ package hfapigo_test

import (
"testing"
"time"

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

func TestSpeechRecognitionRequest(t *testing.T) {
const retries = 10

arResp := &hfapigo.SpeechRecognitionResponse{}
var err error
for i := 0; i < retries; i++ {
arResp, err = hfapigo.SendSpeechRecognitionRequest(hfapigo.RecommendedSpeechRecongnitionModelEnglish, TestFilesDir+"/sample.flac")
if err == nil {
break
} else {
time.Sleep(time.Second * 5)
}
}
arResp, err = hfapigo.SendSpeechRecognitionRequest(hfapigo.RecommendedSpeechRecongnitionModelEnglish, TestFilesDir+"/sample.flac")
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion text_to_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
_ "image/png"
)

const RecommendedTextToImageModel = "runwayml/stable-diffusion-v1-5"
const RecommendedTextToImageModel = "stable-diffusion-v1-5/stable-diffusion-v1-5"

// Request structure for text-to-image model
type TextToImageRequest struct {
Expand Down

0 comments on commit 62b0c96

Please sign in to comment.