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")
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ollama
|
||||
package local
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -15,9 +15,9 @@ func TestDefaultBaseURL(t *testing.T) {
|
||||
require.Equal(t, "http://localhost:11434/v1", DefaultBaseURL)
|
||||
}
|
||||
|
||||
// TestNewOllamaProvider_HitsGivenBaseURL confirms a custom baseURL
|
||||
// TestNewLocalProvider_HitsGivenBaseURL confirms a custom baseURL
|
||||
// overrides the default and is actually what the provider talks to.
|
||||
func TestNewOllamaProvider_HitsGivenBaseURL(t *testing.T) {
|
||||
func TestNewLocalProvider_HitsGivenBaseURL(t *testing.T) {
|
||||
var hit bool
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
hit = true
|
||||
@@ -26,7 +26,7 @@ func TestNewOllamaProvider_HitsGivenBaseURL(t *testing.T) {
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
p := NewOllamaProvider(srv.URL + "/v1")
|
||||
p := NewLocalProvider(srv.URL + "/v1")
|
||||
stream, err := p.ChatStream(context.Background(), llm.ChatRequest{SystemPrompt: "hi"})
|
||||
require.NoError(t, err)
|
||||
for range stream {
|
||||
@@ -34,13 +34,13 @@ func TestNewOllamaProvider_HitsGivenBaseURL(t *testing.T) {
|
||||
require.True(t, hit, "provider did not hit the configured baseURL")
|
||||
}
|
||||
|
||||
// TestNewOllamaProvider_EmptyBaseURLDoesNotPanic confirms the empty ->
|
||||
// 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 TestNewOllamaProvider_EmptyBaseURLDoesNotPanic(t *testing.T) {
|
||||
p := NewOllamaProvider("")
|
||||
func TestNewLocalProvider_EmptyBaseURLDoesNotPanic(t *testing.T) {
|
||||
p := NewLocalProvider("")
|
||||
require.NotNil(t, p)
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
// Package ollama provides an llm.LLMProvider for a local Ollama server
|
||||
// (or any other local server sharing Ollama's OpenAI-compatible endpoint
|
||||
// shape — LM Studio, llama.cpp's server, vLLM). 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 ollama
|
||||
|
||||
import "github.com/sausheong/harness/providers/openai"
|
||||
|
||||
// DefaultBaseURL is Ollama's local OpenAI-compatible endpoint, used when
|
||||
// NewOllamaProvider is called with an empty baseURL.
|
||||
const DefaultBaseURL = "http://localhost:11434/v1"
|
||||
|
||||
// NewOllamaProvider returns an OpenAI-compatible provider pointed at
|
||||
// baseURL, or DefaultBaseURL when baseURL is empty. No API key is
|
||||
// needed — Ollama doesn'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 NewOllamaProvider(baseURL string) *openai.OpenAIProvider {
|
||||
if baseURL == "" {
|
||||
baseURL = DefaultBaseURL
|
||||
}
|
||||
return openai.NewOpenAIProviderWithKind("", baseURL, "local")
|
||||
}
|
||||
Reference in new issue
Block a user