diff --git a/internal/entity/models/modelscope.go b/internal/entity/models/modelscope.go index 5dccc390d..9c937c027 100644 --- a/internal/entity/models/modelscope.go +++ b/internal/entity/models/modelscope.go @@ -72,7 +72,15 @@ type modelscopeModelListResponse struct { // NewModelScopeModel creates a new ModelScope model instance. func NewModelScopeModel(baseURL map[string]string, urlSuffix URLSuffix) *ModelScopeModel { - transport := http.DefaultTransport.(*http.Transport).Clone() + defaultTransport, ok := http.DefaultTransport.(*http.Transport) + var transport *http.Transport + if ok { + transport = defaultTransport.Clone() + } else { + transport = &http.Transport{ + Proxy: http.ProxyFromEnvironment, + } + } transport.MaxIdleConns = 100 transport.MaxIdleConnsPerHost = 10 transport.IdleConnTimeout = 90 * time.Second diff --git a/internal/entity/models/modelscope_test.go b/internal/entity/models/modelscope_test.go index 5a698f569..409d03bad 100644 --- a/internal/entity/models/modelscope_test.go +++ b/internal/entity/models/modelscope_test.go @@ -26,6 +26,12 @@ import ( "time" ) +type roundTripperFunc func(*http.Request) (*http.Response, error) + +func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) { + return f(r) +} + func newModelScopeForTest(baseURL string) *ModelScopeModel { return NewModelScopeModel( map[string]string{"default": baseURL}, @@ -79,6 +85,20 @@ func TestModelScopeFactoryRoute(t *testing.T) { } } +func TestModelScopeNewModelWithCustomDefaultTransport(t *testing.T) { + original := http.DefaultTransport + http.DefaultTransport = roundTripperFunc(func(*http.Request) (*http.Response, error) { + return nil, nil + }) + t.Cleanup(func() { + http.DefaultTransport = original + }) + + if model := NewModelScopeModel(map[string]string{"default": "http://unused"}, URLSuffix{}); model == nil { + t.Fatal("NewModelScopeModel returned nil") + } +} + func TestModelScopeChatHappyPathNormalizesBaseURLAndOmitsEmptyAuth(t *testing.T) { var seen map[string]interface{} srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {