This repository was archived by the owner on Oct 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Normalize Hugging Face Model names to lowercase #39
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a4488b
Add case conversion for Hugging Face model names
ilopezluna 2ecd43d
Using existing desktop mock
ilopezluna cf16bc2
Add name normalization to InspectOpenAI
ilopezluna 6785c7c
Rename to normalizeHuggingFaceModelName because normalization will on…
ilopezluna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| package desktop | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "io" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/docker/pinata/common/pkg/inference/models" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| type mockHTTPClient struct { | ||
| doFunc func(req *http.Request) (*http.Response, error) | ||
| } | ||
|
|
||
| func (m *mockHTTPClient) Do(req *http.Request) (*http.Response, error) { | ||
| return m.doFunc(req) | ||
| } | ||
|
|
||
| func TestPullHuggingFaceModel(t *testing.T) { | ||
| // Test case for pulling a Hugging Face model with mixed case | ||
| modelName := "hf.co/Bartowski/Llama-3.2-1B-Instruct-GGUF" | ||
| expectedLowercase := "hf.co/bartowski/llama-3.2-1b-instruct-gguf" | ||
|
|
||
| client := &Client{ | ||
| dockerClient: &mockHTTPClient{ | ||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||
| // Verify the model name is converted to lowercase in the request | ||
| var reqBody models.ModelCreateRequest | ||
| err := json.NewDecoder(req.Body).Decode(&reqBody) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, expectedLowercase, reqBody.From) | ||
|
|
||
| return &http.Response{ | ||
| StatusCode: http.StatusOK, | ||
| Body: io.NopCloser(bytes.NewBufferString(`{"type":"success","message":"Model pulled successfully"}`)), | ||
| }, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, _, err := client.Pull(modelName, func(s string) {}) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestChatHuggingFaceModel(t *testing.T) { | ||
| // Test case for chatting with a Hugging Face model with mixed case | ||
| modelName := "hf.co/Bartowski/Llama-3.2-1B-Instruct-GGUF" | ||
| expectedLowercase := "hf.co/bartowski/llama-3.2-1b-instruct-gguf" | ||
| prompt := "Hello" | ||
|
|
||
| client := &Client{ | ||
| dockerClient: &mockHTTPClient{ | ||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||
| // Verify the model name is converted to lowercase in the request | ||
| var reqBody OpenAIChatRequest | ||
| err := json.NewDecoder(req.Body).Decode(&reqBody) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, expectedLowercase, reqBody.Model) | ||
|
|
||
| return &http.Response{ | ||
| StatusCode: http.StatusOK, | ||
| Body: io.NopCloser(bytes.NewBufferString("data: {\"choices\":[{\"delta\":{\"content\":\"Hello there!\"}}]}\n")), | ||
| }, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| err := client.Chat(modelName, prompt) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestInspectHuggingFaceModel(t *testing.T) { | ||
| // Test case for inspecting a Hugging Face model with mixed case | ||
| modelName := "hf.co/Bartowski/Llama-3.2-1B-Instruct-GGUF" | ||
| expectedLowercase := "hf.co/bartowski/llama-3.2-1b-instruct-gguf" | ||
|
|
||
| client := &Client{ | ||
| dockerClient: &mockHTTPClient{ | ||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||
| // Verify the model name is converted to lowercase in the request URL | ||
| assert.Contains(t, req.URL.Path, expectedLowercase) | ||
|
|
||
| return &http.Response{ | ||
| StatusCode: http.StatusOK, | ||
| Body: io.NopCloser(bytes.NewBufferString(`{ | ||
| "id": "sha256:123456789012", | ||
| "tags": ["` + expectedLowercase + `"], | ||
| "created": 1234567890, | ||
| "config": { | ||
| "format": "gguf", | ||
| "quantization": "Q4_K_M", | ||
| "parameters": "1B", | ||
| "architecture": "llama", | ||
| "size": "1.2GB" | ||
| } | ||
| }`)), | ||
| }, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| model, err := client.Inspect(modelName) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, expectedLowercase, model.Tags[0]) | ||
| } | ||
|
|
||
| func TestNonHuggingFaceModel(t *testing.T) { | ||
| // Test case for a non-Hugging Face model (should not be converted to lowercase) | ||
| modelName := "docker.io/library/llama2" | ||
| client := &Client{ | ||
| dockerClient: &mockHTTPClient{ | ||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||
| // Verify the model name is not converted to lowercase | ||
| var reqBody models.ModelCreateRequest | ||
| err := json.NewDecoder(req.Body).Decode(&reqBody) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, modelName, reqBody.From) | ||
|
|
||
| return &http.Response{ | ||
| StatusCode: http.StatusOK, | ||
| Body: io.NopCloser(bytes.NewBufferString(`{"type":"success","message":"Model pulled successfully"}`)), | ||
| }, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, _, err := client.Pull(modelName, func(s string) {}) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestPushHuggingFaceModel(t *testing.T) { | ||
| // Test case for pushing a Hugging Face model with mixed case | ||
| modelName := "hf.co/Bartowski/Llama-3.2-1B-Instruct-GGUF" | ||
| expectedLowercase := "hf.co/bartowski/llama-3.2-1b-instruct-gguf" | ||
|
|
||
| client := &Client{ | ||
| dockerClient: &mockHTTPClient{ | ||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||
| // Verify the model name is converted to lowercase in the request URL | ||
| assert.Contains(t, req.URL.Path, expectedLowercase) | ||
|
|
||
| return &http.Response{ | ||
| StatusCode: http.StatusOK, | ||
| Body: io.NopCloser(bytes.NewBufferString(`{"type":"success","message":"Model pushed successfully"}`)), | ||
| }, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, _, err := client.Push(modelName, func(s string) {}) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestRemoveHuggingFaceModel(t *testing.T) { | ||
| // Test case for removing a Hugging Face model with mixed case | ||
| modelName := "hf.co/Bartowski/Llama-3.2-1B-Instruct-GGUF" | ||
| expectedLowercase := "hf.co/bartowski/llama-3.2-1b-instruct-gguf" | ||
|
|
||
| client := &Client{ | ||
| dockerClient: &mockHTTPClient{ | ||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||
| // Verify the model name is converted to lowercase in the request URL | ||
| assert.Contains(t, req.URL.Path, expectedLowercase) | ||
|
|
||
| return &http.Response{ | ||
| StatusCode: http.StatusOK, | ||
| Body: io.NopCloser(bytes.NewBufferString("Model removed successfully")), | ||
| }, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err := client.Remove([]string{modelName}, false) | ||
| assert.NoError(t, err) | ||
| } | ||
|
|
||
| func TestTagHuggingFaceModel(t *testing.T) { | ||
| // Test case for tagging a Hugging Face model with mixed case | ||
| sourceModel := "hf.co/Bartowski/Llama-3.2-1B-Instruct-GGUF" | ||
| expectedLowercase := "hf.co/bartowski/llama-3.2-1b-instruct-gguf" | ||
| targetRepo := "myrepo" | ||
| targetTag := "latest" | ||
|
|
||
| client := &Client{ | ||
| dockerClient: &mockHTTPClient{ | ||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||
| // Verify the model name is converted to lowercase in the request URL | ||
| assert.Contains(t, req.URL.Path, expectedLowercase) | ||
|
|
||
| return &http.Response{ | ||
| StatusCode: http.StatusCreated, | ||
| Body: io.NopCloser(bytes.NewBufferString("Tag created successfully")), | ||
| }, nil | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err := client.Tag(sourceModel, targetRepo, targetTag) | ||
| assert.NoError(t, err) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.