mirror of
https://github.com/ollama/ollama.git
synced 2026-04-17 21:54:08 +02:00
* add ability to disable cloud
Users can now easily opt-out of cloud inference and web search by
setting
```
"disable_ollama_cloud": true
```
in their `~/.ollama/server.json` settings file. After a setting update,
the server must be restarted.
Alternatively, setting the environment variable `OLLAMA_NO_CLOUD=1` will
also disable cloud features. While users previously were able to avoid
cloud models by not pulling or `ollama run`ing them, this gives them an
easy way to enforce that decision. Any attempt to run a cloud model when
cloud is disabled will fail.
The app's old "airplane mode" setting, which did a similar thing for
hiding cloud models within the app is now unified with this new cloud
disabled mode. That setting has been replaced with a "Cloud" toggle,
which behind the scenes edits `server.json` and then restarts the
server.
* gate cloud models across TUI and launch flows when cloud is disabled
Block cloud models from being selected, launched, or written to
integration configs when cloud mode is turned off:
- TUI main menu: open model picker instead of launching with a
disabled cloud model
- cmd.go: add IsCloudModelDisabled checks for all Selection* paths
- LaunchCmd: filter cloud models from saved Editor configs before
launch, fall through to picker if none remain
- Editor Run() methods (droid, opencode, openclaw): filter cloud
models before calling Edit() and persist the cleaned list
- Export SaveIntegration, remove SaveIntegrationModel wrapper that
was accumulating models instead of replacing them
* rename saveIntegration to SaveIntegration in config.go and tests
* cmd/config: add --model guarding and empty model list fixes
* Update docs/faq.mdx
Co-authored-by: Jeffrey Morgan <jmorganca@gmail.com>
* Update internal/cloud/policy.go
Co-authored-by: Jeffrey Morgan <jmorganca@gmail.com>
* Update internal/cloud/policy.go
Co-authored-by: Jeffrey Morgan <jmorganca@gmail.com>
* Update server/routes.go
Co-authored-by: Jeffrey Morgan <jmorganca@gmail.com>
* Revert "Update internal/cloud/policy.go"
This reverts commit 8bff8615f9.
Since this error shows up in other integrations, we want it to be
prefixed with Ollama
* rename cloud status
* more status renaming
* fix tests that weren't updated after rename
---------
Co-authored-by: ParthSareen <parth.sareen@ollama.com>
Co-authored-by: Jeffrey Morgan <jmorganca@gmail.com>
150 lines
3.5 KiB
Go
150 lines
3.5 KiB
Go
//go:build windows || darwin
|
|
|
|
package tools
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/ollama/ollama/auth"
|
|
)
|
|
|
|
type WebSearch struct{}
|
|
|
|
type SearchRequest struct {
|
|
Query string `json:"query"`
|
|
MaxResults int `json:"max_results,omitempty"`
|
|
}
|
|
|
|
type SearchResult struct {
|
|
Title string `json:"title"`
|
|
URL string `json:"url"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
type SearchResponse struct {
|
|
Results []SearchResult `json:"results"`
|
|
}
|
|
|
|
func (w *WebSearch) Name() string {
|
|
return "web_search"
|
|
}
|
|
|
|
func (w *WebSearch) Description() string {
|
|
return "Search the web for real-time information using ollama.com web search API."
|
|
}
|
|
|
|
func (w *WebSearch) Prompt() string {
|
|
return ""
|
|
}
|
|
|
|
func (g *WebSearch) Schema() map[string]any {
|
|
schemaBytes := []byte(`{
|
|
"type": "object",
|
|
"properties": {
|
|
"query": {
|
|
"type": "string",
|
|
"description": "The search query to execute"
|
|
},
|
|
"max_results": {
|
|
"type": "integer",
|
|
"description": "Maximum number of search results to return",
|
|
"default": 3
|
|
}
|
|
},
|
|
"required": ["query"]
|
|
}`)
|
|
var schema map[string]any
|
|
if err := json.Unmarshal(schemaBytes, &schema); err != nil {
|
|
return nil
|
|
}
|
|
return schema
|
|
}
|
|
|
|
func (w *WebSearch) Execute(ctx context.Context, args map[string]any) (any, string, error) {
|
|
rawQuery, ok := args["query"]
|
|
if !ok {
|
|
return nil, "", fmt.Errorf("query parameter is required")
|
|
}
|
|
|
|
queryStr, ok := rawQuery.(string)
|
|
if !ok || strings.TrimSpace(queryStr) == "" {
|
|
return nil, "", fmt.Errorf("query must be a non-empty string")
|
|
}
|
|
|
|
maxResults := 5
|
|
if v, ok := args["max_results"].(float64); ok && int(v) > 0 {
|
|
maxResults = int(v)
|
|
}
|
|
|
|
result, err := performWebSearch(ctx, queryStr, maxResults)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
return result, "", nil
|
|
}
|
|
|
|
func performWebSearch(ctx context.Context, query string, maxResults int) (*SearchResponse, error) {
|
|
if err := ensureCloudEnabledForTool(ctx, "web search is unavailable"); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reqBody := SearchRequest{Query: query, MaxResults: maxResults}
|
|
|
|
jsonBody, err := json.Marshal(reqBody)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to marshal request body: %w", err)
|
|
}
|
|
|
|
searchURL, err := url.Parse("https://ollama.com/api/web_search")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse search URL: %w", err)
|
|
}
|
|
|
|
q := searchURL.Query()
|
|
q.Add("ts", strconv.FormatInt(time.Now().Unix(), 10))
|
|
searchURL.RawQuery = q.Encode()
|
|
|
|
data := fmt.Appendf(nil, "%s,%s", http.MethodPost, searchURL.RequestURI())
|
|
signature, err := auth.Sign(ctx, data)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to sign request: %w", err)
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, searchURL.String(), bytes.NewBuffer(jsonBody))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
|
}
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
if signature != "" {
|
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", signature))
|
|
}
|
|
|
|
client := &http.Client{Timeout: 10 * time.Second}
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to execute search request: %w", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return nil, fmt.Errorf("search API error (status %d)", resp.StatusCode)
|
|
}
|
|
|
|
var result SearchResponse
|
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
|
return nil, fmt.Errorf("failed to decode response: %w", err)
|
|
}
|
|
|
|
return &result, nil
|
|
}
|