From bac96cc4dec5979c38a6b3c701d580b476d570bd Mon Sep 17 00:00:00 2001 From: Kevin Mingtarja Date: Fri, 17 Jan 2025 01:41:14 +0700 Subject: [PATCH] remove localHypermodeModels list and handle 404s properly instead in local dev --- CHANGELOG.md | 2 +- runtime/models/hypermode.go | 14 -------------- runtime/models/models.go | 9 +++++++++ runtime/utils/http.go | 19 +++++++++++++++++-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d2e4b70..30874b956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## UNRELEASED - chore: update api-explorer to react 19 [#700](https://github.com/hypermodeinc/modus/pull/700) -- chore: add meta-llama/llama-3.2-3b-instruct to localHypermodeModels +- chore: remove localHypermodeModels list and handle 404s properly instead in local dev [#703](https://github.com/hypermodeinc/modus/pull/703) - fix: resolve warning in `deserializeRawMap` [#692](https://github.com/hypermodeinc/modus/pull/692) diff --git a/runtime/models/hypermode.go b/runtime/models/hypermode.go index 05cc6173e..d33cf2204 100644 --- a/runtime/models/hypermode.go +++ b/runtime/models/hypermode.go @@ -27,9 +27,6 @@ func getHypermodeModelEndpointUrl(model *manifest.ModelInfo) (string, error) { // In development, use the shared Hypermode model server. // Note: Authentication via the Hypermode CLI is required. if config.IsDevEnvironment() { - if _, ok := localHypermodeModels[strings.ToLower(model.SourceModel)]; !ok { - return "", fmt.Errorf("model %s is not available in the local dev environment", model.SourceModel) - } endpoint := fmt.Sprintf("https://models.hypermode.host/%s", strings.ToLower(model.SourceModel)) return endpoint, nil } @@ -55,14 +52,3 @@ func authenticateHypermodeModelRequest(ctx context.Context, req *http.Request, c // In production, the Hypermode infrastructure protects the model server. return nil } - -// cSpell:disable -// These are the Hypermode models that are available in the local dev environment. -// This list may be updated as new models are added. -var localHypermodeModels = map[string]bool{ - "meta-llama/meta-llama-3.1-8b-instruct": true, - "meta-llama/llama-3.2-3b-instruct": true, - "sentence-transformers/all-minilm-l6-v2": true, - "antoinemc/distilbart-mnli-github-issues": true, - "distilbert/distilbert-base-uncased-finetuned-sst-2-english": true, -} diff --git a/runtime/models/models.go b/runtime/models/models.go index ba577cfb7..a87e4d0ae 100644 --- a/runtime/models/models.go +++ b/runtime/models/models.go @@ -11,11 +11,13 @@ package models import ( "context" + "errors" "fmt" "net/http" "strings" "github.com/hypermodeinc/modus/lib/manifest" + "github.com/hypermodeinc/modus/runtime/config" "github.com/hypermodeinc/modus/runtime/db" "github.com/hypermodeinc/modus/runtime/httpclient" "github.com/hypermodeinc/modus/runtime/manifestdata" @@ -89,6 +91,13 @@ func PostToModelEndpoint[TResult any](ctx context.Context, model *manifest.Model res, err := utils.PostHttp[TResult](ctx, url, payload, bs) if err != nil { var empty TResult + var httpe *utils.HttpError + if errors.As(err, &httpe) { + if config.IsDevEnvironment() && httpe.StatusCode == http.StatusNotFound { + return empty, fmt.Errorf("model %s is not available in the local dev environment", model.SourceModel) + } + } + return empty, err } diff --git a/runtime/utils/http.go b/runtime/utils/http.go index b6f31c6f3..91c560a97 100644 --- a/runtime/utils/http.go +++ b/runtime/utils/http.go @@ -20,6 +20,15 @@ import ( var httpClient = &http.Client{} +type HttpError struct { + StatusCode int + Message string +} + +func (e *HttpError) Error() string { + return "HTTP error: " + e.Message +} + func HttpClient() *http.Client { return httpClient } @@ -38,9 +47,15 @@ func sendHttp(req *http.Request) ([]byte, error) { if response.StatusCode != http.StatusOK { if len(body) == 0 { - return nil, fmt.Errorf("HTTP error: %s", response.Status) + return nil, &HttpError{ + StatusCode: response.StatusCode, + Message: response.Status, + } } else { - return nil, fmt.Errorf("HTTP error: %s\n%s", response.Status, body) + return nil, &HttpError{ + StatusCode: response.StatusCode, + Message: fmt.Sprintf("%s\n%s", response.Status, body), + } } }