repo stringlengths 6 47 | file_url stringlengths 77 269 | file_path stringlengths 5 186 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-07 08:35:43 2026-01-07 08:55:24 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/sparse_common.go | server/sparse_common.go | //go:build !windows
package server
import "os"
func setSparse(*os.File) {
}
| go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/routes_generate_test.go | server/routes_generate_test.go | package server
import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"sync"
"testing"
"time"
"github.com/gin-gonic/gin"
"github.com/google/go-cmp/cmp"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/fs/ggml"
"github.com/ollama/ollama/llm"
"github... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | true |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/prompt.go | server/prompt.go | package server
import (
"bytes"
"context"
"errors"
"fmt"
"log/slog"
"slices"
"strings"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/model/renderers"
"github.com/ollama/ollama/template"
)
type tokenizeFunc func(context.Context, string) ([]int, error)
// chatPromp... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/sparse_windows.go | server/sparse_windows.go | package server
import (
"os"
"golang.org/x/sys/windows"
)
func setSparse(file *os.File) {
// exFat (and other FS types) don't support sparse files, so ignore errors
windows.DeviceIoControl( //nolint:errcheck
windows.Handle(file.Fd()), windows.FSCTL_SET_SPARSE,
nil, 0,
nil, 0,
nil, nil,
)
}
| go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/routes.go | server/routes.go | package server
import (
"bytes"
"cmp"
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"image"
"io"
"io/fs"
"log/slog"
"math"
"math/rand"
"net"
"net/http"
"net/netip"
"net/url"
"os"
"os/signal"
"slices"
"strings"
"sync/atomic"
"syscall"
"time"
"github.com/gin-contrib/cors"
"github.... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | true |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/download.go | server/download.go | package server
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"math"
"math/rand/v2"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"sync/atomic"
"syscall"
"time"
"golang.org/x/sync/errgroup"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/format"... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/routes_list_test.go | server/routes_list_test.go | package server
import (
"encoding/json"
"net/http"
"slices"
"testing"
"github.com/gin-gonic/gin"
"github.com/ollama/ollama/api"
)
func TestList(t *testing.T) {
gin.SetMode(gin.TestMode)
t.Setenv("OLLAMA_MODELS", t.TempDir())
expectNames := []string{
"mistral:7b-instruct-q4_0",
"zephyr:7b-beta-q5_K_M"... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/routes_harmony_streaming_test.go | server/routes_harmony_streaming_test.go | package server
// this test file is to test integration of harmony parser into routes.go (as
// opposed to harmonyparser_test.go, which tests the parser in isolation)
import (
"bytes"
"context"
"encoding/json"
"net/http"
"strings"
"testing"
"time"
"github.com/gin-gonic/gin"
"github.com/ollama/ollama/api"
"... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/images_test.go | server/images_test.go | package server
import (
"strings"
"testing"
"github.com/ollama/ollama/fs/ggml"
"github.com/ollama/ollama/template"
"github.com/ollama/ollama/types/model"
)
func TestModelCapabilities(t *testing.T) {
// Create completion model (llama architecture without vision)
completionModelPath, _ := createBinFile(t, ggml.... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/quantization_test.go | server/quantization_test.go | package server
import (
"bytes"
"fmt"
"math"
"os"
"strings"
"testing"
fsggml "github.com/ollama/ollama/fs/ggml"
"github.com/ollama/ollama/ml/backend/ggml"
)
func TestGetTensorNewType(t *testing.T) {
cases := []struct {
name string
kv map[string]any
qs quantizeState
new... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/cache/blob/cache.go | server/internal/cache/blob/cache.go | // Package blob implements a content-addressable disk cache for blobs and
// manifests.
package blob
import (
"bytes"
"crypto/sha256"
"errors"
"fmt"
"hash"
"io"
"io/fs"
"iter"
"os"
"path/filepath"
"strings"
"time"
"github.com/ollama/ollama/server/internal/internal/names"
)
// Entry contains metadata abo... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/cache/blob/cache_test.go | server/internal/cache/blob/cache_test.go | package blob
import (
"crypto/sha256"
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"time"
"github.com/ollama/ollama/server/internal/testutil"
)
func init() {
debug = true
}
var epoch = func() time.Time {
d := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
if d.IsZero() {... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/cache/blob/casecheck_test.go | server/internal/cache/blob/casecheck_test.go | package blob
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
func isCaseSensitive(dir string) bool {
defer func() {
os.Remove(filepath.Join(dir, "_casecheck"))
}()
exists := func(file string) bool {
_, err := os.Stat(file)
return err == nil
}
file := filepath.Join(dir, "_caseche... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/cache/blob/chunked.go | server/internal/cache/blob/chunked.go | package blob
import (
"crypto/sha256"
"errors"
"io"
"os"
)
// Chunk represents a range of bytes in a blob.
type Chunk struct {
Start int64
End int64
}
// Size returns end minus start plus one.
func (c Chunk) Size() int64 {
return c.End - c.Start + 1
}
// Chunker writes to a blob in chunks.
// Its zero valu... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/cache/blob/digest.go | server/internal/cache/blob/digest.go | package blob
import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"slices"
"strings"
)
var ErrInvalidDigest = errors.New("invalid digest")
// Digest is a blob identifier that is the SHA-256 hash of a blob's content.
//
// It is comparable and can be used as a map key.
type Digest struct {
sum [32]byte
}
//... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/cache/blob/digest_test.go | server/internal/cache/blob/digest_test.go | package blob
import (
"encoding/json"
"testing"
)
func TestParseDigest(t *testing.T) {
cases := []struct {
in string
valid bool
}{
{"sha256-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", true},
{"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", true},
// ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/backoff/backoff_synctest_test.go | server/internal/internal/backoff/backoff_synctest_test.go | //go:build goexperiment.synctest
package backoff
import (
"context"
"errors"
"testing"
"testing/synctest"
"time"
)
func TestLoop(t *testing.T) {
synctest.Run(func() {
last := -1
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
for n, err := range Loop(ctx, 100*time.Millisecond) {
if !... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/backoff/backoff_test.go | server/internal/internal/backoff/backoff_test.go | //go:build goexperiment.synctest
package backoff
import (
"testing"
"testing/synctest"
"time"
)
func TestLoopAllocs(t *testing.T) {
for i := range 3 {
got := testing.AllocsPerRun(1000, func() {
for tick := range Loop(t.Context(), 1) {
if tick >= i {
break
}
}
})
want := float64(0)
if i... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/backoff/backoff.go | server/internal/internal/backoff/backoff.go | package backoff
import (
"context"
"iter"
"math/rand/v2"
"time"
)
func Loop(ctx context.Context, maxBackoff time.Duration) iter.Seq2[int, error] {
var n int
return func(yield func(int, error) bool) {
var t *time.Timer
for {
if ctx.Err() != nil {
yield(n, ctx.Err())
return
}
if !yield(n, ni... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/names/name.go | server/internal/internal/names/name.go | package names
import (
"cmp"
"fmt"
"strings"
"github.com/ollama/ollama/server/internal/internal/stringsx"
)
const MaxNameLength = 350 + 1 + 80 + 1 + 80 + 1 + 80 // <host>/<namespace>/<model>:<tag>
type Name struct {
// Make incomparable to enfoce use of Compare / Equal for
// case-insensitive comparisons.
_ ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/names/name_test.go | server/internal/internal/names/name_test.go | package names
import (
"strings"
"testing"
)
func TestParseName(t *testing.T) {
cases := []struct {
in string
want Name
}{
{"", Name{}},
{"m:t", Name{m: "m", t: "t"}},
{"m", Name{m: "m"}},
{"/m", Name{m: "m"}},
{"/n/m:t", Name{n: "n", m: "m", t: "t"}},
{"n/m", Name{n: "n", m: "m"}},
{"n/m:t", ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/stringsx/stringsx.go | server/internal/internal/stringsx/stringsx.go | // Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
// Package stringsx provides additional string manipulation functions
// that aren't in the standard library's strings package or go4.org/mem.
package stringsx
import (
"unicode"
"unicode/utf8"
)
// CompareFold returns -1, 0, or 1 de... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/stringsx/stringsx_test.go | server/internal/internal/stringsx/stringsx_test.go | // Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package stringsx
import (
"cmp"
"strings"
"testing"
)
func TestCompareFold(t *testing.T) {
tests := []struct {
a, b string
}{
// Basic ASCII cases
{"", ""},
{"a", "a"},
{"a", "A"},
{"A", "a"},
{"a", "b"},
{"b", "a"... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/syncs/line.go | server/internal/internal/syncs/line.go | // Package syncs provides synchronization primitives.
package syncs
import (
"cmp"
"io"
"sync"
)
var closedChan = func() chan struct{} {
ch := make(chan struct{})
close(ch)
return ch
}()
// Ticket represents a ticket in a sequence of tickets. The zero value is
// invalid. Use [Line.Take] to get a valid ticket.... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/syncs/line_test.go | server/internal/internal/syncs/line_test.go | //go:build goexperiment.synctest
package syncs
import (
"bytes"
"io"
"math/rand/v2"
"testing"
"testing/synctest"
)
func TestPipelineReadWriterTo(t *testing.T) {
for range 10 {
synctest.Run(func() {
q := NewRelayReader()
tickets := []struct {
io.WriteCloser
s string
}{
{q.Take(), "you"},... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/internal/syncs/syncs.go | server/internal/internal/syncs/syncs.go | package syncs
import (
"sync"
"sync/atomic"
)
// Group is a [sync.WaitGroup] with a Go method.
type Group struct {
wg sync.WaitGroup
n atomic.Int64
}
func (g *Group) Go(f func()) {
g.wg.Add(1)
go func() {
g.n.Add(1) // Now we are running
defer func() {
g.wg.Done()
g.n.Add(-1) // Now we are done
}(... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/client/ollama/registry_synctest_test.go | server/internal/client/ollama/registry_synctest_test.go | // TODO: go:build goexperiment.synctest
package ollama
import (
"context"
"errors"
"io"
"net/http"
"strings"
"testing"
"time"
)
func TestPullDownloadTimeout(t *testing.T) {
rc, ctx := newRegistryClient(t, func(w http.ResponseWriter, r *http.Request) {
defer t.Log("upstream", r.Method, r.URL.Path)
switch ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/client/ollama/registry.go | server/internal/client/ollama/registry.go | // Package ollama provides a client for interacting with an Ollama registry
// which pushes and pulls model manifests and layers as defined by the
// [ollama.com/manifest].
package ollama
import (
"bufio"
"bytes"
"cmp"
"context"
"crypto"
"crypto/ed25519"
"crypto/sha256"
"crypto/tls"
"encoding/base64"
"encodi... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/client/ollama/trace.go | server/internal/client/ollama/trace.go | package ollama
import (
"context"
)
// Trace is a set of functions that are called to report progress during blob
// downloads and uploads.
//
// Use [WithTrace] to attach a Trace to a context for use with [Registry.Push]
// and [Registry.Pull].
type Trace struct {
// Update is called during [Registry.Push] and [Re... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/client/ollama/registry_test.go | server/internal/client/ollama/registry_test.go | package ollama
import (
"bytes"
"cmp"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
"net"
"net/http"
"net/http/httptest"
"os"
"reflect"
"strings"
"sync/atomic"
"testing"
"github.com/ollama/ollama/server/internal/cache/blob"
"github.com/ollama/ollama/server/internal/testutil"
)
func ExampleR... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/testutil/testutil.go | server/internal/testutil/testutil.go | package testutil
import (
"bytes"
"io"
"log/slog"
"os"
"path/filepath"
"testing"
"time"
)
// LogWriter returns an [io.Writer] that logs each Write using t.Log.
func LogWriter(t *testing.T) io.Writer {
return testWriter{t}
}
type testWriter struct{ t *testing.T }
func (w testWriter) Write(b []byte) (int, err... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/manifest/manifest.go | server/internal/manifest/manifest.go | // Package manifest provides documentation for the Ollama manifest format.
// This package contains no code.
//
// # Manifests
//
// A manifest is a JSON object that describes a model. The JSON object has a
// single field "layers" which is a list of layers that make up the model.
// A layer is a single, logical unit o... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/registry/server_test.go | server/internal/registry/server_test.go | package registry
import (
"bytes"
"context"
"encoding/json"
"io"
"io/fs"
"net"
"net/http"
"net/http/httptest"
"os"
"regexp"
"strings"
"sync"
"testing"
"github.com/ollama/ollama/server/internal/cache/blob"
"github.com/ollama/ollama/server/internal/client/ollama"
"github.com/ollama/ollama/server/interna... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/server/internal/registry/server.go | server/internal/registry/server.go | // Package registry implements an http.Handler for handling local Ollama API
// model management requests. See [Local] for details.
package registry
import (
"cmp"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"slices"
"strings"
"sync"
"time"
"github.com/ollama/ollama/server/interna... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/format/time.go | format/time.go | package format
import (
"fmt"
"math"
"strings"
"time"
)
// humanDuration returns a human-readable approximation of a
// duration (eg. "About a minute", "4 hours ago", etc.).
func humanDuration(d time.Duration) string {
seconds := int(d.Seconds())
switch {
case seconds < 1:
return "Less than a second"
case ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/format/time_test.go | format/time_test.go | package format
import (
"testing"
"time"
)
func assertEqual(t *testing.T, a any, b any) {
if a != b {
t.Errorf("Assert failed, expected %v, got %v", b, a)
}
}
func TestHumanTime(t *testing.T) {
now := time.Now()
t.Run("zero value", func(t *testing.T) {
assertEqual(t, HumanTime(time.Time{}, "never"), "neve... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/format/bytes_test.go | format/bytes_test.go | package format
import (
"testing"
)
func TestHumanBytes(t *testing.T) {
type testCase struct {
input int64
expected string
}
tests := []testCase{
// Test bytes (B)
{0, "0 B"},
{1, "1 B"},
{999, "999 B"},
// Test kilobytes (KB)
{1000, "1 KB"},
{1500, "1.5 KB"},
{999999, "999 KB"},
// Te... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/format/format.go | format/format.go | package format
import (
"fmt"
"math"
"strconv"
)
const (
Thousand = 1000
Million = Thousand * 1000
Billion = Million * 1000
)
func HumanNumber(b uint64) string {
switch {
case b >= Billion:
number := float64(b) / Billion
if number == math.Floor(number) {
return fmt.Sprintf("%.0fB", number) // no dec... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/format/bytes.go | format/bytes.go | package format
import (
"fmt"
"math"
)
const (
Byte = 1
KiloByte = Byte * 1000
MegaByte = KiloByte * 1000
GigaByte = MegaByte * 1000
TeraByte = GigaByte * 1000
KibiByte = Byte * 1024
MebiByte = KibiByte * 1024
GibiByte = MebiByte * 1024
)
func HumanBytes(b int64) string {
var value float64
var unit str... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/format/format_test.go | format/format_test.go | package format
import (
"testing"
)
func TestHumanNumber(t *testing.T) {
type testCase struct {
input uint64
expected string
}
testCases := []testCase{
{0, "0"},
{999, "999"},
{1000, "1K"},
{1001, "1K"},
{1000000, "1M"},
{125000000, "125M"},
{500500000, "500.50M"},
{500550000, "500.55M"},
... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/thinking/parser.go | thinking/parser.go | package thinking
import (
"strings"
"unicode"
)
type thinkingState int
const (
// We're looking for the opening tag, but we haven't seen any non-whitespace
// characters yet
thinkingState_LookingForOpening thinkingState = iota
// We've seen the opening tag, but we haven't seen any non-whitespace
// characters... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/thinking/parser_test.go | thinking/parser_test.go | package thinking
import (
"testing"
)
func TestExtractThinking(t *testing.T) {
tests := []struct {
in, wantContent, wantThink string
}{
{
in: "<think> internal </think> world",
wantThink: "internal ",
wantContent: "world",
},
{
in: "<think>a</think><think>b</think>c",
wan... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/thinking/template_test.go | thinking/template_test.go | package thinking
import (
"testing"
"text/template"
)
func TestInferThinkingTags(t *testing.T) {
cases := []struct {
desc string
tmplString string
wantOpeningTag string
wantClosingTag string
}{
{
desc: "basic",
tmplString: `
{{ if .Thinking}}
/think
{{ end }}
{{- range $... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/thinking/template.go | thinking/template.go | package thinking
import (
"strings"
"text/template"
"text/template/parse"
)
func templateVisit(n parse.Node, enterFn func(parse.Node) bool, exitFn func(parse.Node)) {
if n == nil {
return
}
shouldContinue := enterFn(n)
if !shouldContinue {
return
}
switch x := n.(type) {
case *parse.ListNode:
for _, c... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/cpu_linux_test.go | discover/cpu_linux_test.go | package discover
import (
"bytes"
"log/slog"
"testing"
)
func TestLinuxCPUDetails(t *testing.T) {
type results struct {
cores int
efficiency int
threads int
}
type testCase struct {
input string
expCPUs []results
expThreadCount int
}
testCases := map[string]*testCase{
"#5... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | true |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/cpu_linux.go | discover/cpu_linux.go | package discover
import (
"bufio"
"errors"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"github.com/ollama/ollama/format"
)
func GetCPUMem() (memInfo, error) {
mem, err := getCPUMem()
if err != nil {
return memInfo{}, err
}
return getCPUMemByCgroups(mem)... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/runner_test.go | discover/runner_test.go | package discover
import (
"log/slog"
"os"
"testing"
)
func init() {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
slog.SetDefault(logger)
}
func TestFilterOverlapByLibrary(t *testing.T) {
type testcase struct {
name string
inp map[string]map[string]map[st... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/types.go | discover/types.go | package discover
import (
"log/slog"
"path/filepath"
"sort"
"strings"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/ml"
)
type memInfo struct {
TotalMemory uint64 `json:"total_memory,omitempty"`
FreeMemory uint64 `json:"free_memory,omitempty"`
FreeSwap uint64 `json:"free_swap,omitempty"` /... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/gpu.go | discover/gpu.go | package discover
import (
"log/slog"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"time"
"github.com/ollama/ollama/logutil"
"github.com/ollama/ollama/ml"
)
// Jetson devices have JETSON_JETPACK="x.y.z" factory set to the Jetpack version installed.
// Included to drive logic for reducing Ollama-allocated over... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/runner.go | discover/runner.go | package discover
// Runner based GPU discovery
import (
"context"
"io"
"log/slog"
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/llm"
"github.com/ollama/ollama/logutil"
... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/cpu_windows_test.go | discover/cpu_windows_test.go | package discover
import "testing"
func TestProcessSystemLogicalProcessorInforationList(t *testing.T) {
type pkgs struct {
cores int
efficiency int
threads int
}
type testCase struct {
input []byte
expected []pkgs
}
testCases := map[string]*testCase{
"AMD64 Family 25 Model 97 Stepping 2 ": ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | true |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/gpu_darwin.go | discover/gpu_darwin.go | package discover
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
#include "gpu_info_darwin.h"
*/
import "C"
import (
"log/slog"
"syscall"
"github.com/ollama/ollama/format"
)
const (
metalMinimumMemory = 512 * format.MebiByte
)
func GetCPUMem() (memInf... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/discover/cpu_windows.go | discover/cpu_windows.go | package discover
import (
"fmt"
"log/slog"
"syscall"
"unsafe"
"github.com/ollama/ollama/logutil"
)
type MEMORYSTATUSEX struct {
length uint32
MemoryLoad uint32
TotalPhys uint64
AvailPhys uint64
TotalPageFile uint64
AvailPageFile uint64
TotalVirt... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/parser/parser.go | parser/parser.go | package parser
import (
"bufio"
"bytes"
"crypto/sha256"
"errors"
"fmt"
"io"
"net/http"
"os"
"os/user"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
"sync"
"golang.org/x/mod/semver"
"golang.org/x/sync/errgroup"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
"github.com... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/parser/expandpath_test.go | parser/expandpath_test.go | package parser
import (
"os"
"os/user"
"path/filepath"
"runtime"
"testing"
)
func TestExpandPath(t *testing.T) {
mockCurrentUser := func() (*user.User, error) {
return &user.User{
Username: "testuser",
HomeDir: func() string {
if os.PathSeparator == '\\' {
return filepath.FromSlash("D:/home/tes... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/parser/parser_test.go | parser/parser_test.go | package parser
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"io"
"maps"
"os"
"path/filepath"
"strings"
"testing"
"unicode/utf16"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/text/encoding"
"golang.org/x/te... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/config.go | fs/config.go | package fs
type Config interface {
Architecture() string
String(string, ...string) string
Uint(string, ...uint32) uint32
Float(string, ...float32) float32
Bool(string, ...bool) bool
Strings(string, ...[]string) []string
Ints(string, ...[]int32) []int32
Floats(string, ...[]float32) []float32
Bools(string, ...... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/util/bufioutil/buffer_seeker.go | fs/util/bufioutil/buffer_seeker.go | package bufioutil
import (
"bufio"
"io"
)
type BufferedSeeker struct {
rs io.ReadSeeker
br *bufio.Reader
}
func NewBufferedSeeker(rs io.ReadSeeker, size int) *BufferedSeeker {
return &BufferedSeeker{
rs: rs,
br: bufio.NewReaderSize(rs, size),
}
}
func (b *BufferedSeeker) Read(p []byte) (int, error) {
ret... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/util/bufioutil/buffer_seeker_test.go | fs/util/bufioutil/buffer_seeker_test.go | package bufioutil
import (
"bytes"
"io"
"strings"
"testing"
)
func TestBufferedSeeker(t *testing.T) {
const alphabet = "abcdefghijklmnopqrstuvwxyz"
bs := NewBufferedSeeker(strings.NewReader(alphabet), 0) // minReadBufferSize = 16
checkRead := func(buf []byte, expected string) {
t.Helper()
_, err := bs.Re... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/ggml/gguf.go | fs/ggml/gguf.go | package ggml
import (
"bytes"
"cmp"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"log/slog"
"maps"
"os"
"runtime"
"slices"
"strings"
"golang.org/x/sync/errgroup"
)
type containerGGUF struct {
ByteOrder binary.ByteOrder
Version uint32
V1 struct {
NumTensor uint32
NumKV uint32
}
V2 struct ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/ggml/ggml_test.go | fs/ggml/ggml_test.go | package ggml
import (
"maps"
"math"
"slices"
"strconv"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestTensorLayers(t *testing.T) {
tensors := make(map[string]*Tensor)
for _, name := range []string{
"token_embd.weight",
"blk.0.attn_k.weight",
"blk.0.attn_output.weight",
"blk.0.attn_q.w... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/ggml/gguf_test.go | fs/ggml/gguf_test.go | package ggml
import (
"bytes"
"math/rand/v2"
"os"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestWriteGGUF(t *testing.T) {
b := bytes.NewBuffer(make([]byte, 2*3))
for range 8 {
t.Run("shuffle", func(t *testing.T) {
t.Parallel()
ts := []*Tensor{
{Name: "token_embd.weight", Shape: [... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/ggml/type.go | fs/ggml/type.go | package ggml
import (
"fmt"
"log/slog"
"strings"
)
// FileType is the Go equivalent to llama_ftype used for gguf file typing
type FileType uint32
const (
FileTypeF32 FileType = iota
FileTypeF16
fileTypeQ4_0
fileTypeQ4_1
fileTypeMXFP4 // originally fileTypeQ4_1_F16 // unused by GGML
fileTypeQ4_2 // unused b... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/ggml/ggml.go | fs/ggml/ggml.go | package ggml
import (
"cmp"
"encoding/binary"
"errors"
"fmt"
"io"
"log/slog"
"math"
"slices"
"strings"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/fs/util/bufioutil"
"github.com/ollama/ollama/ml"
)
type GGML struct {
container
model
Length int64
}
type model interface {
KV() KV
Tens... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/gguf/lazy.go | fs/gguf/lazy.go | package gguf
import (
"encoding/binary"
"iter"
"log/slog"
)
type lazy[T any] struct {
count uint64
next func() (T, bool)
stop func()
values []T
// successFunc is called when all values have been successfully read.
successFunc func() error
}
func newLazy[T any](f *File, fn func() (T, error)) (*lazy[T],... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/gguf/gguf.go | fs/gguf/gguf.go | package gguf
import (
"bytes"
"cmp"
"encoding/binary"
"errors"
"fmt"
"io"
"iter"
"os"
"slices"
"strings"
)
const (
typeUint8 uint32 = iota
typeInt8
typeUint16
typeInt16
typeUint32
typeInt32
typeFloat32
typeBool
typeString
typeArray
typeUint64
typeInt64
typeFloat64
)
var ErrUnsupported = errors... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/gguf/tensor.go | fs/gguf/tensor.go | package gguf
import (
"log/slog"
"strings"
)
type TensorInfo struct {
Name string
Offset uint64
Shape []uint64
Type TensorType
}
func (ti TensorInfo) Valid() bool {
return ti.Name != "" && ti.NumBytes() > 0
}
func (ti TensorInfo) NumValues() int64 {
var numItems int64 = 1
for _, dim := range ti.Shape ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/gguf/keyvalue.go | fs/gguf/keyvalue.go | package gguf
import (
"reflect"
"slices"
)
type KeyValue struct {
Key string
Value
}
func (kv KeyValue) Valid() bool {
return kv.Key != "" && kv.Value.value != nil
}
type Value struct {
value any
}
func value[T any](v Value, kinds ...reflect.Kind) (t T) {
vv := reflect.ValueOf(v.value)
if slices.Contains(k... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/gguf/reader.go | fs/gguf/reader.go | package gguf
import (
"bufio"
"io"
)
type bufferedReader struct {
offset int64
*bufio.Reader
}
func newBufferedReader(rs io.ReadSeeker, size int) *bufferedReader {
return &bufferedReader{
Reader: bufio.NewReaderSize(rs, size),
}
}
func (rs *bufferedReader) Read(p []byte) (n int, err error) {
n, err = rs.Re... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/gguf/keyvalue_test.go | fs/gguf/keyvalue_test.go | package gguf
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func split(name string, values map[string][]any) (matched []any, unmatched []any) {
for key, value := range values {
if key == name {
matched = value
} else {
unmatched = append(unmatched, value...)
}
}
return
}
func TestValue(t *test... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/fs/gguf/gguf_test.go | fs/gguf/gguf_test.go | package gguf_test
import (
"bytes"
"os"
"strconv"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/ollama/ollama/fs/ggml"
"github.com/ollama/ollama/fs/gguf"
)
func createBinFile(tb testing.TB) string {
tb.Helper()
f, err := os.CreateTemp(tb.TempDir(), "... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/logutil/logutil.go | logutil/logutil.go | package logutil
import (
"context"
"io"
"log/slog"
"path/filepath"
"runtime"
"time"
)
const LevelTrace slog.Level = -8
func NewLogger(w io.Writer, level slog.Level) *slog.Logger {
return slog.New(slog.NewTextHandler(w, &slog.HandlerOptions{
Level: level,
AddSource: true,
ReplaceAttr: func(_ []string... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/envconfig/config.go | envconfig/config.go | package envconfig
import (
"fmt"
"log/slog"
"math"
"net"
"net/url"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
)
// Host returns the scheme and host. Host can be configured via the OLLAMA_HOST environment variable.
// Default is scheme "http" and host "127.0.0.1:11434"
func Host() *url.URL {
... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/envconfig/config_test.go | envconfig/config_test.go | package envconfig
import (
"log/slog"
"math"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/ollama/ollama/logutil"
)
func TestHost(t *testing.T) {
cases := map[string]struct {
value string
expect string
}{
"empty": {"", "http://127.0.0.1:11434"},
"only address": {"1... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_mllama.go | convert/convert_mllama.go | package convert
import (
"strings"
"github.com/ollama/ollama/fs/ggml"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
)
type mllamaModel struct {
ModelParameters
TextModel struct {
llamaModel
CrossAttentionLayers []int32 `json:"cross_attention_layers"`
} `json:"text_config"`
VisionModel s... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/reader_torch.go | convert/reader_torch.go | package convert
import (
"io"
"io/fs"
"strings"
"github.com/nlpodyssey/gopickle/pytorch"
"github.com/nlpodyssey/gopickle/types"
)
func parseTorch(fsys fs.FS, replacer *strings.Replacer, ps ...string) ([]Tensor, error) {
var ts []Tensor
for _, p := range ps {
pt, err := pytorch.Load(p)
if err != nil {
r... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_mixtral.go | convert/convert_mixtral.go | package convert
import (
"fmt"
"github.com/ollama/ollama/fs/ggml"
)
type mixtralModel struct {
llamaModel
NumLocalExperts uint32 `json:"num_local_experts"`
NumExpertsPerToken uint32 `json:"num_experts_per_tok"`
}
func (p *mixtralModel) KV(t *Tokenizer) ggml.KV {
kv := p.llamaModel.KV(t)
if p.NumLocalExpe... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_deepseek2.go | convert/convert_deepseek2.go | package convert
import (
"cmp"
"fmt"
"log/slog"
"regexp"
"strconv"
"github.com/ollama/ollama/fs/ggml"
)
type deepseek2Model struct {
ModelParameters // architectures, vocab_size
MaxPositionEmbeddings uint32 `json:"max_position_embeddings"`
HiddenSize uint32 `json:"hidden_size"`
H... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/reader_safetensors.go | convert/reader_safetensors.go | package convert
import (
"bufio"
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
"maps"
"slices"
"strings"
"github.com/d4l3k/go-bfloat16"
"github.com/x448/float16"
)
type safetensorMetadata struct {
Type string `json:"dtype"`
Shape []uint64 `json:"shape"`
Offsets []int64 ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_gemma2.go | convert/convert_gemma2.go | package convert
import "github.com/ollama/ollama/fs/ggml"
type gemma2Model struct {
gemmaModel
SlidingWindow uint32 `json:"sliding_window"`
AttentionLogitSoftcap float32 `json:"attn_logit_softcapping"`
FinalLogitSoftcap float32 `json:"final_logit_softcapping"`
}
func (p *gemma2Model) KV(t *Tokenizer... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/tensor_test.go | convert/tensor_test.go | package convert
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"iter"
"math/rand/v2"
"slices"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/ollama/ollama/fs/ggml"
"github.com/pdevine/tensor"
)
type fakeTensor struct {
name string
shape []uint64
data []float32
repacker Repacker
}
f... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_gemma3n.go | convert/convert_gemma3n.go | package convert
import (
"slices"
"strings"
"github.com/ollama/ollama/fs/ggml"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
"gonum.org/v1/gonum/stat/distuv"
)
type gemma3nModel struct {
ModelParameters
TextModel struct {
ActivationSparsityPattern []float32 `json:"activation_sparsity_patt... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_nomicbert.go | convert/convert_nomicbert.go | package convert
import (
"cmp"
"encoding/json"
"io/fs"
"path/filepath"
"slices"
"strings"
"github.com/ollama/ollama/fs/ggml"
)
type nomicbertModel struct {
ModelParameters
NLayers uint32 `json:"n_layers"`
NumHiddenLayers uint32 `json:"num_hidden_layers"`
MaxPositionEmbeddings uint32 ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_mistral.go | convert/convert_mistral.go | package convert
import (
"cmp"
"fmt"
"strings"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
"github.com/ollama/ollama/fs/ggml"
)
type mistral3Model struct {
ModelParameters
ImageTokenIndex uint32 `json:"image_token_index"`
SpatialMergeSize uint32 `json:"spatial_merge_size"`
VisionFe... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_test.go | convert/convert_test.go | package convert
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"io"
"io/fs"
"log/slog"
"maps"
"os"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/ollama/ollama/fs/ggml"
)
type tensorData struct {
Offsets []int... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_phi3.go | convert/convert_phi3.go | package convert
import (
"cmp"
"encoding/binary"
"io"
"math"
"strings"
"sync"
"github.com/ollama/ollama/fs/ggml"
)
type phi3Model struct {
ModelParameters
NumHiddenLayers uint32 `json:"num_hidden_layers"`
NLayers uint32 `json:"n_layers"`
HiddenSize uint32 `json:"hidden_size"`
NEmbd ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/tensor.go | convert/tensor.go | package convert
import (
"cmp"
"errors"
"io"
"iter"
"path"
"slices"
"strconv"
"strings"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
"github.com/ollama/ollama/fs/ggml"
)
type split struct {
*strings.Replacer
dim int
slices []tensor.Slice
// afterFunc is an optional function to a... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/tokenizer.go | convert/tokenizer.go | package convert
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io/fs"
"log/slog"
"maps"
"os"
"slices"
"strings"
)
const (
_ int32 = iota
tokenTypeNormal
tokenTypeUnknown
tokenTypeControl
tokenTypeUserDefined
tokenTypeUnused
tokenTypeByte
)
type Tokenizer struct {
*Vocabula... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/tokenizer_spm.go | convert/tokenizer_spm.go | package convert
import (
"cmp"
"encoding/json"
"errors"
"fmt"
"io/fs"
"log/slog"
"os"
"reflect"
"slices"
"google.golang.org/protobuf/proto"
"github.com/ollama/ollama/convert/sentencepiece"
)
func parseSentencePiece(fsys fs.FS) (*Vocabulary, error) {
slog.Debug("using spm vocabulary")
ast, err := parse... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_deepseekocr.go | convert/convert_deepseekocr.go | package convert
import (
"fmt"
"github.com/ollama/ollama/fs/ggml"
)
type deepseekocr struct {
ModelParameters
LanguageConfig struct {
MaxPositionEmbeddings uint32 `json:"max_position_embeddings"`
HiddenSize uint32 `json:"hidden_size"`
HiddenLayers uint32 `json:"num_hidden_layers"`
Int... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert.go | convert/convert.go | package convert
import (
"cmp"
"encoding/json"
"errors"
"fmt"
"io/fs"
"log/slog"
"os"
"slices"
"strings"
"github.com/ollama/ollama/fs/ggml"
)
type ModelParameters struct {
Architectures []string `json:"architectures"`
VocabSize uint32 `json:"vocab_size"`
TextModel struct {
VocabSize uint32 `jso... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_gemma2_adapter.go | convert/convert_gemma2_adapter.go | package convert
import (
"strings"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
"github.com/ollama/ollama/fs/ggml"
)
type gemma2Adapter struct {
AdapterParameters
}
var _ AdapterConverter = (*gemma2Adapter)(nil)
func (p *gemma2Adapter) KV(baseKV ggml.KV) ggml.KV {
kv := p.AdapterParameters... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/reader.go | convert/reader.go | package convert
import (
"errors"
"io"
"io/fs"
"strings"
)
type Tensor interface {
Name() string
Shape() []uint64
Kind() uint32
SetRepacker(Repacker)
WriteTo(io.Writer) (int64, error)
Clone() Tensor
}
type tensorBase struct {
name string
shape []uint64
repacker Repacker
}
func (t tensorBase) Nam... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/reader_test.go | convert/reader_test.go | package convert
import (
"bytes"
"encoding/binary"
"os"
"path/filepath"
"testing"
"github.com/d4l3k/go-bfloat16"
"github.com/google/go-cmp/cmp"
"github.com/x448/float16"
)
func TestSafetensors(t *testing.T) {
t.Parallel()
root, err := os.OpenRoot(t.TempDir())
if err != nil {
t.Fatal(err)
}
defer root... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_gptoss.go | convert/convert_gptoss.go | package convert
import (
"bytes"
"cmp"
"encoding/binary"
"io"
"slices"
"strings"
"github.com/ollama/ollama/fs/ggml"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
)
type gptossModel struct {
ModelParameters
HiddenLayers uint32 `json:"num_hidden_layers"`
MaxPositionEmbeddings uin... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_gemma.go | convert/convert_gemma.go | package convert
import (
"strings"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
"github.com/ollama/ollama/fs/ggml"
)
type gemmaModel struct {
ModelParameters
MaxPositionEmbeddings uint32 `json:"max_position_embeddings"`
HiddenSize uint32 `json:"hidden_size"`
HiddenLayers ... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_gemma3.go | convert/convert_gemma3.go | package convert
import (
"cmp"
"slices"
"github.com/ollama/ollama/fs/ggml"
)
type gemma3Model struct {
gemmaModel
Architecture string
TextModel struct {
HeadDim uint32 `json:"head_dim"`
HiddenSize uint32 `json:"hidden_size"`
HiddenLayers uint32 `json:"num_hidden_layers"`
Intermedi... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_llama4.go | convert/convert_llama4.go | package convert
import (
"slices"
"strings"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"
"github.com/ollama/ollama/fs/ggml"
)
type llama4Model struct {
ModelParameters
TextModel struct {
llamaModel
NumExpertsPerToken uint32 `json:"num_experts_per_tok"`
NumLocalExperts uint3... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/tokenizer_test.go | convert/tokenizer_test.go | package convert
import (
"io"
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
func createTokenizerFS(t *testing.T, dir string, files map[string]io.Reader) fs.FS {
t.Helper()
for k, v := range files {
if err := func() error {
f, err := os.Create(filepath.Join(dir, k))
... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
ollama/ollama | https://github.com/ollama/ollama/blob/626af2d80973270c4d59b8df7153ac47ad67ed7b/convert/convert_olmo.go | convert/convert_olmo.go | package convert
import (
"cmp"
"github.com/ollama/ollama/fs/ggml"
)
type ropeScaling struct {
Factor float32 `json:"factor"`
OriginalMaxPositionEmbeds uint32 `json:"original_max_position_embeddings"`
AttentionFactor float32 `json:"attention_factor"`
BetaFast float... | go | MIT | 626af2d80973270c4d59b8df7153ac47ad67ed7b | 2026-01-07T08:35:43.337630Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.