From 58b1b335e4ba7a844505c1da02e06b4d25e0801f Mon Sep 17 00:00:00 2001 From: Tanner Kvarfordt Date: Mon, 30 Sep 2024 17:19:57 -0700 Subject: [PATCH 1/3] Fail unit tests early if no API key is detected --- setup_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/setup_test.go b/setup_test.go index 28b7d96..657d5cb 100644 --- a/setup_test.go +++ b/setup_test.go @@ -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) - } } From 44400fe1d940f12b1250fd107cdf367c30f95582 Mon Sep 17 00:00:00 2001 From: Tanner Kvarfordt Date: Mon, 30 Sep 2024 17:31:08 -0700 Subject: [PATCH 2/3] Updated text-to-image model to a mirror of the old model --- text_to_image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text_to_image.go b/text_to_image.go index 51f0780..cf7a2c7 100644 --- a/text_to_image.go +++ b/text_to_image.go @@ -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 { From 232a3c17924f226498173dc782e72aad814aca32 Mon Sep 17 00:00:00 2001 From: Tanner Kvarfordt Date: Mon, 30 Sep 2024 17:33:04 -0700 Subject: [PATCH 3/3] Removed retries in models that don't have a wait-for-model option as they were causing rate limits --- audio_classification_test.go | 12 +----------- image_to_text_test.go | 12 +----------- object_detection_test.go | 12 +----------- speech_recognition_test.go | 12 +----------- 4 files changed, 4 insertions(+), 44 deletions(-) diff --git a/audio_classification_test.go b/audio_classification_test.go index b70d48e..3f208b2 100644 --- a/audio_classification_test.go +++ b/audio_classification_test.go @@ -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) } diff --git a/image_to_text_test.go b/image_to_text_test.go index 8c76e98..1294777 100644 --- a/image_to_text_test.go +++ b/image_to_text_test.go @@ -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) } diff --git a/object_detection_test.go b/object_detection_test.go index f484858..70e31f9 100644 --- a/object_detection_test.go +++ b/object_detection_test.go @@ -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) } diff --git a/speech_recognition_test.go b/speech_recognition_test.go index 712726f..ab80094 100644 --- a/speech_recognition_test.go +++ b/speech_recognition_test.go @@ -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) }