2026-04-27 20:35:47 +08:00
|
|
|
//
|
|
|
|
|
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
2026-05-06 10:41:58 +08:00
|
|
|
"ragflow/internal/common"
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
"strings"
|
2026-04-27 20:35:47 +08:00
|
|
|
|
|
|
|
|
"google.golang.org/genai"
|
|
|
|
|
)
|
|
|
|
|
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
type googleModelPage struct {
|
2026-06-11 13:32:50 +08:00
|
|
|
items []DSModel
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
nextPageToken string
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 19:01:00 +08:00
|
|
|
func collectGoogleModelNames(ctx context.Context, listPage func(context.Context, string) (googleModelPage, error)) ([]ListModelResponse, error) {
|
2026-06-11 13:32:50 +08:00
|
|
|
var models []DSModel
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
pageToken := ""
|
|
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
page, err := listPage(ctx, pageToken)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-11 13:32:50 +08:00
|
|
|
models = append(models, page.items...)
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
if page.nextPageToken == "" {
|
2026-06-11 13:32:50 +08:00
|
|
|
return ParseListModel(ModelList{Models: models}), nil
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
}
|
|
|
|
|
pageToken = page.nextPageToken
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 19:01:00 +08:00
|
|
|
var googleListModels = func(ctx context.Context, config *genai.ClientConfig) ([]ListModelResponse, error) {
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
client, err := genai.NewClient(ctx, config)
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return collectGoogleModelNames(ctx, func(ctx context.Context, pageToken string) (googleModelPage, error) {
|
|
|
|
|
models, err := client.Models.List(ctx, &genai.ListModelsConfig{PageToken: pageToken})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return googleModelPage{}, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-11 13:32:50 +08:00
|
|
|
var modelNames []DSModel
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
for _, m := range models.Items {
|
2026-06-11 13:32:50 +08:00
|
|
|
modelName := strings.TrimSpace(m.DisplayName)
|
|
|
|
|
if modelName == "" {
|
|
|
|
|
modelName = strings.TrimSpace(m.Name)
|
|
|
|
|
}
|
|
|
|
|
if modelName != "" {
|
|
|
|
|
modelNames = append(modelNames, DSModel{
|
|
|
|
|
ID: modelName,
|
|
|
|
|
OwnedBy: "Google",
|
|
|
|
|
})
|
|
|
|
|
}
|
fix(go): wire Google CheckConnection to ListModels (#14660)
### What problem does this PR solve?
Closes #14703
`GoogleModel.CheckConnection` currently returns a hardcoded `no such
method` error even though the Google Go driver already supports
`ListModels`. This makes provider connection checks fail regardless of
whether the configured API key can list Google models.
This PR makes `CheckConnection` call `ListModels`, adds a small API-key
guard for nil, empty, and whitespace-only keys, and keeps `ListModels`
useful by following paginated Google model responses.
### What stays unchanged
* Google model listing still uses the Google GenAI SDK with
`genai.BackendGeminiAPI`.
* Model names still come from `models.Items[*].Name`.
* `Balance`, `Encode`, chat, streaming, provider config, and factory
wiring are unchanged.
### Tests and validation
Added focused unit coverage for:
* `CheckConnection` delegating to `ListModels` and returning its error
* nil, missing, empty, and whitespace-only API key validation
* model-name passthrough from the list-models adapter
* paginated model listing, empty-result preservation, and next-page
error propagation
Validated current PR head `17ceef43515ba8c46c254dd349b9085bf26dcbea`
locally with Go 1.25.0:
* `go test ./internal/entity/models -run
'TestGoogleModel|TestCollectGoogleModelNames' -count=1 -v` - PASS
* `go test ./internal/entity/models -count=1` - PASS
* `go test -race ./internal/entity/models -count=1` - PASS
* `gofmt -w internal/entity/models/google.go
internal/entity/models/google_test.go` - PASS, no diff
* `git diff --check` - PASS
### Type of change
* [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Jin Hai <haijin.chn@gmail.com>
2026-05-11 05:25:17 +02:00
|
|
|
}
|
|
|
|
|
return googleModelPage{items: modelNames, nextPageToken: models.NextPageToken}, nil
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GoogleModel implements ModelDriver for Google AI
|
2026-04-27 20:35:47 +08:00
|
|
|
type GoogleModel struct {
|
2026-06-04 17:50:22 +08:00
|
|
|
baseModel BaseModel
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewGoogleModel creates a new Google AI model instance
|
|
|
|
|
func NewGoogleModel(baseURL map[string]string, urlSuffix URLSuffix) *GoogleModel {
|
|
|
|
|
return &GoogleModel{
|
2026-06-04 17:50:22 +08:00
|
|
|
baseModel: BaseModel{
|
|
|
|
|
BaseURL: baseURL,
|
|
|
|
|
URLSuffix: urlSuffix,
|
|
|
|
|
},
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) NewInstance(baseURL map[string]string) ModelDriver {
|
2026-06-04 17:50:22 +08:00
|
|
|
return NewGoogleModel(baseURL, g.baseModel.URLSuffix)
|
2026-04-29 17:05:08 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) Name() string {
|
2026-04-27 20:35:47 +08:00
|
|
|
return "google"
|
|
|
|
|
}
|
|
|
|
|
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
func (g *GoogleModel) clientConfig(apiKey string, apiConfig *APIConfig) *genai.ClientConfig {
|
|
|
|
|
return &genai.ClientConfig{APIKey: apiKey, Backend: genai.BackendGeminiAPI, HTTPOptions: genai.HTTPOptions{BaseURL: g.baseURL(apiConfig)}}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *GoogleModel) baseURL(apiConfig *APIConfig) string {
|
2026-06-04 17:50:22 +08:00
|
|
|
baseURL, err := g.baseModel.GetBaseURL(apiConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
defaultConfig := &APIConfig{}
|
|
|
|
|
if apiConfig != nil {
|
|
|
|
|
defaultConfig.BaseURL = apiConfig.BaseURL
|
|
|
|
|
}
|
|
|
|
|
baseURL, err = g.baseModel.GetBaseURL(defaultConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ""
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
}
|
|
|
|
|
}
|
2026-06-04 17:50:22 +08:00
|
|
|
return strings.TrimSpace(baseURL)
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) ChatWithMessages(modelName string, messages []Message, apiConfig *APIConfig, chatModelConfig *ChatConfig) (*ChatResponse, error) {
|
2026-06-04 17:50:22 +08:00
|
|
|
if err := g.baseModel.APIConfigCheck(apiConfig); err != nil {
|
|
|
|
|
return nil, err
|
2026-04-30 15:25:01 +08:00
|
|
|
}
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
if strings.TrimSpace(modelName) == "" {
|
|
|
|
|
return nil, fmt.Errorf("model name is empty")
|
|
|
|
|
}
|
2026-04-30 15:25:01 +08:00
|
|
|
|
|
|
|
|
if len(messages) == 0 {
|
|
|
|
|
return nil, fmt.Errorf("messages is empty")
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-27 20:35:47 +08:00
|
|
|
ctx := context.Background()
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
client, err := genai.NewClient(ctx, g.clientConfig(strings.TrimSpace(*apiConfig.ApiKey), apiConfig))
|
2026-04-27 20:35:47 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-30 15:25:01 +08:00
|
|
|
// Convert messages to Google SDK format
|
|
|
|
|
var contents []*genai.Content
|
|
|
|
|
for _, msg := range messages {
|
|
|
|
|
var role genai.Role
|
|
|
|
|
switch msg.Role {
|
|
|
|
|
case "user":
|
|
|
|
|
role = genai.RoleUser
|
|
|
|
|
case "model", "assistant":
|
|
|
|
|
role = genai.RoleModel
|
|
|
|
|
default:
|
|
|
|
|
role = genai.RoleUser
|
|
|
|
|
}
|
2026-04-27 20:35:47 +08:00
|
|
|
|
2026-04-30 15:25:01 +08:00
|
|
|
// Handle content based on type
|
|
|
|
|
switch c := msg.Content.(type) {
|
|
|
|
|
case string:
|
|
|
|
|
contents = append(contents, genai.NewContentFromText(c, role))
|
|
|
|
|
case []interface{}:
|
|
|
|
|
// Multimodal content - group parts within a single content
|
|
|
|
|
var parts []*genai.Part
|
|
|
|
|
for _, item := range c {
|
|
|
|
|
if itemMap, ok := item.(map[string]interface{}); ok {
|
|
|
|
|
contentType, _ := itemMap["type"].(string)
|
|
|
|
|
switch contentType {
|
|
|
|
|
case "text":
|
|
|
|
|
if text, ok := itemMap["text"].(string); ok {
|
|
|
|
|
parts = append(parts, genai.NewPartFromText(text))
|
|
|
|
|
}
|
|
|
|
|
case "image_url":
|
|
|
|
|
if imgMap, ok := itemMap["image_url"].(map[string]interface{}); ok {
|
|
|
|
|
if url, ok := imgMap["url"].(string); ok {
|
|
|
|
|
parts = append(parts, genai.NewPartFromURI(url, "image/jpeg"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(parts) > 0 {
|
|
|
|
|
contents = append(contents, genai.NewContentFromParts(parts, role))
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-30 15:25:01 +08:00
|
|
|
// Generate content (non-streaming)
|
|
|
|
|
response, err := client.Models.GenerateContent(ctx, modelName, contents, nil)
|
2026-04-27 20:35:47 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-30 15:25:01 +08:00
|
|
|
// Extract text from response
|
|
|
|
|
answer := response.Text()
|
2026-04-27 20:35:47 +08:00
|
|
|
|
2026-04-30 15:25:01 +08:00
|
|
|
return &ChatResponse{Answer: &answer}, nil
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-30 19:33:57 +08:00
|
|
|
// ChatStreamlyWithSender sends messages and streams response via sender function (best performance, no channel)
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) ChatStreamlyWithSender(modelName string, messages []Message, apiConfig *APIConfig, chatModelConfig *ChatConfig, sender func(*string, *string) error) error {
|
2026-06-04 17:50:22 +08:00
|
|
|
if err := g.baseModel.APIConfigCheck(apiConfig); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-30 19:33:57 +08:00
|
|
|
if len(messages) == 0 {
|
|
|
|
|
return fmt.Errorf("messages is empty")
|
|
|
|
|
}
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
if strings.TrimSpace(modelName) == "" {
|
|
|
|
|
return fmt.Errorf("model name is empty")
|
|
|
|
|
}
|
|
|
|
|
if sender == nil {
|
|
|
|
|
return fmt.Errorf("sender is nil")
|
|
|
|
|
}
|
2026-04-30 19:33:57 +08:00
|
|
|
|
2026-04-27 20:35:47 +08:00
|
|
|
ctx := context.Background()
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
client, err := genai.NewClient(ctx, g.clientConfig(strings.TrimSpace(*apiConfig.ApiKey), apiConfig))
|
2026-04-27 20:35:47 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2026-04-30 19:33:57 +08:00
|
|
|
|
|
|
|
|
// Convert messages to Google SDK format
|
|
|
|
|
var contents []*genai.Content
|
|
|
|
|
for _, msg := range messages {
|
|
|
|
|
var role genai.Role
|
|
|
|
|
switch msg.Role {
|
|
|
|
|
case "user":
|
|
|
|
|
role = genai.RoleUser
|
|
|
|
|
case "model", "assistant":
|
|
|
|
|
role = genai.RoleModel
|
|
|
|
|
default:
|
|
|
|
|
role = genai.RoleUser
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle content based on type
|
|
|
|
|
switch c := msg.Content.(type) {
|
|
|
|
|
case string:
|
|
|
|
|
contents = append(contents, genai.NewContentFromText(c, role))
|
|
|
|
|
case []interface{}:
|
|
|
|
|
// Multimodal content - group parts within a single content
|
|
|
|
|
var parts []*genai.Part
|
|
|
|
|
for _, item := range c {
|
|
|
|
|
if itemMap, ok := item.(map[string]interface{}); ok {
|
|
|
|
|
contentType, _ := itemMap["type"].(string)
|
|
|
|
|
switch contentType {
|
|
|
|
|
case "text":
|
|
|
|
|
if text, ok := itemMap["text"].(string); ok {
|
|
|
|
|
parts = append(parts, genai.NewPartFromText(text))
|
|
|
|
|
}
|
|
|
|
|
case "image_url":
|
|
|
|
|
if imgMap, ok := itemMap["image_url"].(map[string]interface{}); ok {
|
|
|
|
|
if url, ok := imgMap["url"].(string); ok {
|
|
|
|
|
parts = append(parts, genai.NewPartFromURI(url, "image/jpeg"))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(parts) > 0 {
|
|
|
|
|
contents = append(contents, genai.NewContentFromParts(parts, role))
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
2026-04-30 19:33:57 +08:00
|
|
|
|
2026-04-27 20:35:47 +08:00
|
|
|
for response, err := range client.Models.GenerateContentStream(
|
|
|
|
|
ctx,
|
2026-04-30 19:33:57 +08:00
|
|
|
modelName,
|
2026-04-27 20:35:47 +08:00
|
|
|
contents,
|
|
|
|
|
nil,
|
|
|
|
|
) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content := response.Text()
|
|
|
|
|
|
|
|
|
|
var responseContent string
|
2026-04-30 19:33:57 +08:00
|
|
|
if chatModelConfig != nil && chatModelConfig.Thinking != nil && *chatModelConfig.Thinking {
|
2026-06-09 05:26:52 -06:00
|
|
|
if len(response.Candidates) > 0 &&
|
|
|
|
|
response.Candidates[0].Content != nil &&
|
|
|
|
|
len(response.Candidates[0].Content.Parts) > 0 {
|
|
|
|
|
responseContent = response.Candidates[0].Content.Parts[0].Text
|
|
|
|
|
}
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if responseContent != "" {
|
2026-05-06 10:41:58 +08:00
|
|
|
common.Info(fmt.Sprintf("Thinking: %s", responseContent))
|
2026-04-27 20:35:47 +08:00
|
|
|
if err = sender(nil, &responseContent); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if content != "" {
|
2026-05-06 10:41:58 +08:00
|
|
|
common.Info(fmt.Sprintf("Answer: %s", content))
|
2026-04-27 20:35:47 +08:00
|
|
|
if err = sender(&content, nil); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 14:45:30 +08:00
|
|
|
// Embed generates embeddings for a batch of texts using the Gemini embeddings API.
|
2026-05-10 23:24:21 -04:00
|
|
|
// The SDK routes to batchEmbedContents internally, so all texts are sent in one request.
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) Embed(modelName *string, texts []string, apiConfig *APIConfig, embeddingConfig *EmbeddingConfig) ([]EmbeddingData, error) {
|
2026-06-04 17:50:22 +08:00
|
|
|
if err := g.baseModel.APIConfigCheck(apiConfig); err != nil {
|
|
|
|
|
return nil, err
|
2026-05-10 23:24:21 -04:00
|
|
|
}
|
|
|
|
|
if modelName == nil || *modelName == "" {
|
|
|
|
|
return nil, fmt.Errorf("model name is required")
|
|
|
|
|
}
|
|
|
|
|
if len(texts) == 0 {
|
|
|
|
|
return nil, fmt.Errorf("texts is empty")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), nonStreamCallTimeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
client, err := genai.NewClient(ctx, g.clientConfig(strings.TrimSpace(*apiConfig.ApiKey), apiConfig))
|
2026-05-10 23:24:21 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to create client: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents := make([]*genai.Content, len(texts))
|
|
|
|
|
for i, text := range texts {
|
|
|
|
|
contents[i] = genai.NewContentFromText(text, genai.RoleUser)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cfg *genai.EmbedContentConfig
|
|
|
|
|
if embeddingConfig != nil && embeddingConfig.Dimension > 0 {
|
|
|
|
|
dim := int32(embeddingConfig.Dimension)
|
|
|
|
|
cfg = &genai.EmbedContentConfig{OutputDimensionality: &dim}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp, err := client.Models.EmbedContent(ctx, *modelName, contents, cfg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to embed content: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(resp.Embeddings) != len(texts) {
|
|
|
|
|
return nil, fmt.Errorf("expected %d embeddings, got %d", len(texts), len(resp.Embeddings))
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-11 14:45:30 +08:00
|
|
|
result := make([]EmbeddingData, len(resp.Embeddings))
|
2026-05-10 23:24:21 -04:00
|
|
|
for i, emb := range resp.Embeddings {
|
|
|
|
|
vec := make([]float64, len(emb.Values))
|
|
|
|
|
for j, v := range emb.Values {
|
|
|
|
|
vec[j] = float64(v)
|
|
|
|
|
}
|
2026-05-11 14:45:30 +08:00
|
|
|
result[i] = EmbeddingData{
|
|
|
|
|
Embedding: vec,
|
|
|
|
|
Index: i,
|
|
|
|
|
}
|
2026-05-10 23:24:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result, nil
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-09 19:01:00 +08:00
|
|
|
func (g *GoogleModel) ListModels(apiConfig *APIConfig) ([]ListModelResponse, error) {
|
2026-06-04 17:50:22 +08:00
|
|
|
if err := g.baseModel.APIConfigCheck(apiConfig); err != nil {
|
|
|
|
|
return nil, err
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
fix(go-models): apply custom Google base URLs (#15385)
## Summary
- Add custom `base_url` support to the Google Go model driver.
- Preserve Google URL suffix configuration when creating custom base URL
driver instances.
- Validate Google chat/stream request inputs before constructing the SDK
client.
- Cover Google model listing, connection checks, base URL resolution,
and request validation with focused tests.
## What changed
- `GoogleModel.NewInstance` now returns a Google driver configured with
the supplied base URL map.
- Google SDK client creation now resolves configured base URLs through
`genai.HTTPOptions.BaseURL`.
- Base URL lookup supports configured regions, empty-region keys, and
`default` fallback.
- Google chat, streaming chat, embeddings, and model listing now reject
blank API keys before creating SDK clients.
- Google chat and streaming chat now reject blank model names locally,
and streaming chat rejects a nil sender.
- Existing message handling, embeddings, pagination, and provider errors
are preserved.
## Why
Google custom model instances could not use configured base URLs because
`NewInstance` returned `nil` and the SDK client path ignored the driver
base URL map. The request validation keeps invalid Google calls from
reaching SDK client construction with blank credentials or incomplete
chat inputs.
2026-06-01 04:24:29 -07:00
|
|
|
return googleListModels(context.Background(), g.clientConfig(strings.TrimSpace(*apiConfig.ApiKey), apiConfig))
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) Balance(apiConfig *APIConfig) (map[string]interface{}, error) {
|
2026-04-27 20:35:47 +08:00
|
|
|
return nil, fmt.Errorf("no such method")
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) CheckConnection(apiConfig *APIConfig) error {
|
|
|
|
|
_, err := g.ListModels(apiConfig)
|
2026-05-10 23:24:21 -04:00
|
|
|
return err
|
2026-04-27 20:35:47 +08:00
|
|
|
}
|
2026-04-28 12:59:01 +08:00
|
|
|
|
2026-05-09 17:41:54 +08:00
|
|
|
// Rerank calculates similarity scores between query and documents
|
2026-05-12 17:17:44 +08:00
|
|
|
func (g *GoogleModel) Rerank(modelName *string, query string, documents []string, apiConfig *APIConfig, rerankConfig *RerankConfig) (*RerankResponse, error) {
|
|
|
|
|
return nil, fmt.Errorf("%s, Rerank not implemented", g.Name())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TranscribeAudio transcribe audio
|
|
|
|
|
func (g *GoogleModel) TranscribeAudio(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig) (*ASRResponse, error) {
|
|
|
|
|
return nil, fmt.Errorf("%s, no such method", g.Name())
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 14:09:07 +08:00
|
|
|
func (g *GoogleModel) TranscribeAudioWithSender(modelName *string, file *string, apiConfig *APIConfig, asrConfig *ASRConfig, sender func(*string, *string) error) error {
|
|
|
|
|
return fmt.Errorf("%s, no such method", g.Name())
|
2026-05-12 17:17:44 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-15 18:41:43 +08:00
|
|
|
// AudioSpeech convert text to audio
|
|
|
|
|
func (g *GoogleModel) AudioSpeech(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig) (*TTSResponse, error) {
|
2026-05-12 17:17:44 +08:00
|
|
|
return nil, fmt.Errorf("%s, no such method", g.Name())
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 14:09:07 +08:00
|
|
|
func (g *GoogleModel) AudioSpeechWithSender(modelName *string, audioContent *string, apiConfig *APIConfig, ttsConfig *TTSConfig, sender func(*string, *string) error) error {
|
|
|
|
|
return fmt.Errorf("%s, no such method", g.Name())
|
2026-05-12 17:17:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OCRFile OCR file
|
2026-05-15 12:29:52 +08:00
|
|
|
func (g *GoogleModel) OCRFile(modelName *string, content []byte, url *string, apiConfig *APIConfig, ocrConfig *OCRConfig) (*OCRFileResponse, error) {
|
2026-05-12 17:17:44 +08:00
|
|
|
return nil, fmt.Errorf("%s, no such method", g.Name())
|
2026-04-28 12:59:01 +08:00
|
|
|
}
|
2026-05-15 12:29:52 +08:00
|
|
|
|
|
|
|
|
// ParseFile parse file
|
2026-06-03 14:09:07 +08:00
|
|
|
func (g *GoogleModel) ParseFile(modelName *string, content []byte, url *string, apiConfig *APIConfig, parseFileConfig *ParseFileConfig) (*ParseFileResponse, error) {
|
|
|
|
|
return nil, fmt.Errorf("%s, no such method", g.Name())
|
2026-05-15 12:29:52 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-03 14:09:07 +08:00
|
|
|
func (g *GoogleModel) ListTasks(apiConfig *APIConfig) ([]ListTaskStatus, error) {
|
|
|
|
|
return nil, fmt.Errorf("%s, no such method", g.Name())
|
2026-05-15 12:29:52 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-03 14:09:07 +08:00
|
|
|
func (g *GoogleModel) ShowTask(taskID string, apiConfig *APIConfig) (*TaskResponse, error) {
|
|
|
|
|
return nil, fmt.Errorf("%s, no such method", g.Name())
|
2026-05-15 12:29:52 +08:00
|
|
|
}
|