Skip to content

Commit

Permalink
remove localHypermodeModels list and handle 404s properly instead in …
Browse files Browse the repository at this point in the history
…local dev
  • Loading branch information
kevinmingtarja committed Jan 16, 2025
1 parent d9e5683 commit bac96cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions runtime/models/hypermode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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,
}
9 changes: 9 additions & 0 deletions runtime/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
19 changes: 17 additions & 2 deletions runtime/utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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),
}
}
}

Expand Down

0 comments on commit bac96cc

Please sign in to comment.