feat: Google (Gemini) provider on the official Gen AI SDK
Phase 4: provider/google on google.golang.org/genai v1.59.0 — lazy cached client, FunctionResponse tool loop, raw-JSON-schema tools and structured output, ThinkingLevel reasoning mapping, iter.Pull2 streaming, hermetic httptest suite via HTTPOptions.BaseURL. Registry wires google + gemini schemes to the real client; stub machinery deleted (all built-ins real). ADR-0011; README matrix + CLAUDE.md synced. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+17
-56
@@ -1,19 +1,16 @@
|
||||
package majordomo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/llm"
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/anthropic"
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/google"
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/ollama"
|
||||
"gitea.stevedudenhoeffer.com/steve/majordomo/provider/openai"
|
||||
)
|
||||
|
||||
// Built-in provider names. Real client implementations land per-phase
|
||||
// (see progress.md); until a provider's phase ships, its registration is a
|
||||
// stub that resolves (so specs parse and env DSNs load) but errors on use.
|
||||
// Built-in provider names.
|
||||
const (
|
||||
ProviderOpenAI = "openai"
|
||||
ProviderAnthropic = "anthropic"
|
||||
@@ -85,57 +82,21 @@ func registerBuiltins(r *Registry, httpClient *http.Client) {
|
||||
)...), nil
|
||||
}
|
||||
|
||||
// Google lands in its own phase; stub until then.
|
||||
r.providers[ProviderGoogle] = &stubProvider{name: ProviderGoogle, kind: ProviderGoogle}
|
||||
r.schemes[ProviderGoogle] = stubScheme(ProviderGoogle)
|
||||
// "gemini" is an alternate scheme for the Google provider.
|
||||
r.schemes["gemini"] = stubScheme(ProviderGoogle)
|
||||
}
|
||||
|
||||
func stubScheme(kind string) SchemeFactory {
|
||||
return func(name string, dsn DSN) (llm.Provider, error) {
|
||||
return &stubProvider{name: name, kind: kind, baseURL: dsn.BaseURL(), token: dsn.Token}, nil
|
||||
// Google (Gemini) on the official SDK; "gemini" is an alternate scheme.
|
||||
googleOpts := func(extra ...google.Option) []google.Option {
|
||||
if httpClient != nil {
|
||||
extra = append(extra, google.WithHTTPClient(httpClient))
|
||||
}
|
||||
return extra
|
||||
}
|
||||
}
|
||||
|
||||
// stubProvider stands in for a provider implementation that lands in a
|
||||
// later phase. It resolves and carries its connection details (so Parse,
|
||||
// chains, and env loading are fully functional) but errors on use.
|
||||
type stubProvider struct {
|
||||
name string
|
||||
kind string
|
||||
baseURL string
|
||||
token string
|
||||
}
|
||||
|
||||
func (s *stubProvider) Name() string { return s.name }
|
||||
|
||||
func (s *stubProvider) Model(id string, opts ...llm.ModelOption) (llm.Model, error) {
|
||||
cfg := llm.ApplyModelOptions(opts)
|
||||
return &stubModel{provider: s, id: id, cfg: cfg}, nil
|
||||
}
|
||||
|
||||
type stubModel struct {
|
||||
provider *stubProvider
|
||||
id string
|
||||
cfg llm.ModelConfig
|
||||
}
|
||||
|
||||
func (m *stubModel) err() error {
|
||||
return fmt.Errorf("majordomo: provider %q (%s) is not implemented yet", m.provider.name, m.provider.kind)
|
||||
}
|
||||
|
||||
func (m *stubModel) Generate(context.Context, llm.Request, ...llm.Option) (*llm.Response, error) {
|
||||
return nil, m.err()
|
||||
}
|
||||
|
||||
func (m *stubModel) Stream(context.Context, llm.Request, ...llm.Option) (llm.Stream, error) {
|
||||
return nil, m.err()
|
||||
}
|
||||
|
||||
func (m *stubModel) Capabilities() llm.Capabilities {
|
||||
if m.cfg.Capabilities != nil {
|
||||
return *m.cfg.Capabilities
|
||||
r.providers[ProviderGoogle] = google.New(googleOpts()...)
|
||||
googleScheme := func(name string, dsn DSN) (llm.Provider, error) {
|
||||
return google.New(googleOpts(
|
||||
google.WithName(name),
|
||||
google.WithBaseURL(dsn.BaseURL()),
|
||||
google.WithAPIKey(dsn.Token),
|
||||
)...), nil
|
||||
}
|
||||
return llm.Capabilities{}
|
||||
r.schemes[ProviderGoogle] = googleScheme
|
||||
r.schemes["gemini"] = googleScheme
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user