Rename providers/ollama to providers/local
Ollama is one local-model server among several (LM Studio, llama.cpp's server, vLLM, ...) that all speak the same OpenAI-compatible shape — naming the package (and provider name downstream) after one of them was misleading. Same constructor, same default endpoint (Ollama's, being the most common), just generically named: NewLocalProvider. This renames a package published minutes ago in v0.3.8 with no other known consumers yet, so no compatibility shim is kept.
This commit is contained in:
1 parent
3b5aadb31f
commit
50b791d3b6
5 files changed
+45
-43
No files matched your search
@@ -0,0 +1,28 @@
|
||||
// Package local provides an llm.LLMProvider for a locally-served model —
|
||||
// Ollama, LM Studio, llama.cpp's server, vLLM, or anything else exposing
|
||||
// an OpenAI-compatible endpoint on the caller's own machine or network.
|
||||
// Like providers/litellm and providers/openrouter, this adds no new
|
||||
// request/stream-translation code of its own — it's a thin constructor
|
||||
// around harness's existing OpenAI-compatible support.
|
||||
package local
|
||||
|
||||
import "github.com/sausheong/harness/providers/openai"
|
||||
|
||||
// DefaultBaseURL is used when NewLocalProvider is called with an empty
|
||||
// baseURL. It's Ollama's endpoint specifically — the most common local
|
||||
// server — but any other one works the same way via an explicit baseURL.
|
||||
const DefaultBaseURL = "http://localhost:11434/v1"
|
||||
|
||||
// NewLocalProvider returns an OpenAI-compatible provider pointed at
|
||||
// baseURL, or DefaultBaseURL when baseURL is empty. No API key is
|
||||
// needed — local servers generally don't authenticate requests.
|
||||
// kind="local" suppresses reasoning_effort, since locally-served models
|
||||
// don't uniformly support it, and keeps retryable-error classification
|
||||
// from treating a down local server the way it would a hosted API
|
||||
// outage (see llm/retry.go).
|
||||
func NewLocalProvider(baseURL string) *openai.OpenAIProvider {
|
||||
if baseURL == "" {
|
||||
baseURL = DefaultBaseURL
|
||||
}
|
||||
return openai.NewOpenAIProviderWithKind("", baseURL, "local")
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/sausheong/harness/llm"
|
||||
)
|
||||
|
||||
func TestDefaultBaseURL(t *testing.T) {
|
||||
require.Equal(t, "http://localhost:11434/v1", DefaultBaseURL)
|
||||
}
|
||||
|
||||
// TestNewLocalProvider_HitsGivenBaseURL confirms a custom baseURL
|
||||
// overrides the default and is actually what the provider talks to.
|
||||
func TestNewLocalProvider_HitsGivenBaseURL(t *testing.T) {
|
||||
var hit bool
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
hit = true
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
_, _ = w.Write([]byte("data: [DONE]\n\n"))
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
p := NewLocalProvider(srv.URL + "/v1")
|
||||
stream, err := p.ChatStream(context.Background(), llm.ChatRequest{SystemPrompt: "hi"})
|
||||
require.NoError(t, err)
|
||||
for range stream {
|
||||
}
|
||||
require.True(t, hit, "provider did not hit the configured baseURL")
|
||||
}
|
||||
|
||||
// TestNewLocalProvider_EmptyBaseURLDoesNotPanic confirms the empty ->
|
||||
// DefaultBaseURL fallback path constructs a usable provider (the actual
|
||||
// outbound host isn't inspectable from outside the openai package —
|
||||
// OpenAIProvider's client config is unexported — so this checks the
|
||||
// fallback doesn't panic or return nil, and DefaultBaseURL's own value
|
||||
// is asserted separately above).
|
||||
func TestNewLocalProvider_EmptyBaseURLDoesNotPanic(t *testing.T) {
|
||||
p := NewLocalProvider("")
|
||||
require.NotNil(t, p)
|
||||
}
|
||||
Reference in new issue
Block a user