Skip to content

Commit

Permalink
push up for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-gray101 committed Mar 27, 2024
1 parent a51ec8c commit 13282fb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
12 changes: 7 additions & 5 deletions core/http/ctx/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ func NewFiberContextExtractor(ml *model.ModelLoader, appConfig *config.Applicati
// Takes a model string as input which should be the one received from the user request.
// It returns the model name resolved from the context and an error if any.
func (fce *FiberContextExtractor) ModelFromContext(ctx *fiber.Ctx, modelInput string, firstModel bool) (string, error) {
if ctx.Params("model") != "" {
modelInput = ctx.Params("model")
ctxPM := ctx.Params("model")
if ctxPM != "" {
log.Debug().Msgf("[FCE] Overriding param modelInput %q with ctx.Params value %q", modelInput, ctxPM)
modelInput = ctxPM
}

// Set model from bearer token, if available
Expand All @@ -43,16 +45,16 @@ func (fce *FiberContextExtractor) ModelFromContext(ctx *fiber.Ctx, modelInput st
models, _ := fce.ml.ListModels()
if len(models) > 0 {
modelInput = models[0]
log.Debug().Msgf("No model specified, using: %s", modelInput)
log.Debug().Msgf("[FCE] No model specified, using first available: %s", modelInput)
} else {
log.Debug().Msgf("No model specified, returning error")
log.Debug().Msgf("[FCE] No model specified, none available, returning error")
return "", fmt.Errorf("no model specified")
}
}

// If a model is found in bearer token takes precedence
if bearerExists {
log.Debug().Msgf("Using model from bearer token: %s", bearer)
log.Debug().Msgf("[FCE] Using model from bearer token: %s", bearer)
modelInput = bearer
}
return modelInput, nil
Expand Down
7 changes: 6 additions & 1 deletion pkg/utils/base64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import (
"io"
"net/http"
"strings"
"time"
)

var base64DownloadClient http.Client = http.Client{
Timeout: 30 * time.Second,
}

// this function check if the string is an URL, if it's an URL downloads the image in memory
// encodes it in base64 and returns the base64 string

Expand All @@ -18,7 +23,7 @@ import (
func GetImageURLAsBase64(s string) (string, error) {
if strings.HasPrefix(s, "http") {
// download the image
resp, err := http.Get(s)
resp, err := base64DownloadClient.Get(s)
if err != nil {
return "", err
}
Expand Down
Binary file added tests/e2e-aio/e2e-aio.test
Binary file not shown.
1 change: 1 addition & 0 deletions tests/e2e-aio/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var _ = Describe("E2E test", func() {
openai.ImageRequest{
Prompt: "test",
Size: openai.CreateImageSize512x512,
Model: "stablediffusion", // Specify this to avoid relying on ListModels order?
//ResponseFormat: openai.CreateImageResponseFormatURL,
},
)
Expand Down

0 comments on commit 13282fb

Please sign in to comment.