Skip to content

Commit

Permalink
Merge branch 'ollama:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
likelovewant committed Aug 7, 2024
2 parents 63a5f50 + de4fc29 commit ca312b3
Show file tree
Hide file tree
Showing 84 changed files with 524 additions and 315 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
llm/ext_server/* linguist-vendored
* text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ jobs:
if: ${{ startsWith(matrix.os, 'macos-') }}
- uses: golangci/golangci-lint-action@v6
with:
args: --timeout 8m0s -v ${{ startsWith(matrix.os, 'windows-') && '' || '--disable gofmt --disable goimports' }}
args: --timeout 8m0s -v
test:
strategy:
matrix:
Expand Down
18 changes: 14 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@ linters:
- bodyclose
- containedctx
- contextcheck
- errcheck
- exportloopref
- gci
- gocheckcompilerdirectives
# conditionally enable this on linux/macos
# - gofmt
# - goimports
- gofmt
- gofumpt
- gosimple
- govet
- ineffassign
- intrange
- makezero
- misspell
- nilerr
- nolintlint
- nosprintfhostport
- staticcheck
- tenv
- testifylint
- unconvert
- unused
- usestdlibvars
- wastedassign
- whitespace
- usestdlibvars
linters-settings:
gci:
sections: [standard, default, localmodule]
severity:
default-severity: error
rules:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Here are some example models that can be downloaded:
| Llama 3.1 | 405B | 231GB | `ollama run llama3.1:405b` |
| Phi 3 Mini | 3.8B | 2.3GB | `ollama run phi3` |
| Phi 3 Medium | 14B | 7.9GB | `ollama run phi3:medium` |
| Gemma 2 | 2B | 1.6GB | `ollama run gemma2:2b` |
| Gemma 2 | 9B | 5.5GB | `ollama run gemma2` |
| Gemma 2 | 27B | 16GB | `ollama run gemma2:27b` |
| Mistral | 7B | 4.1GB | `ollama run mistral` |
Expand Down Expand Up @@ -318,6 +319,7 @@ See the [API documentation](./docs/api.md) for all endpoints.
- [Sidellama](https://github.com/gyopak/sidellama) (browser-based LLM client)
- [LLMStack](https://github.com/trypromptly/LLMStack) (No-code multi-agent framework to build LLM agents and workflows)
- [BoltAI for Mac](https://boltai.com) (AI Chat Client for Mac)
- [Harbor](https://github.com/av/harbor) (Containerized LLM Toolkit with Ollama as default backend)

### Terminal

Expand Down
3 changes: 2 additions & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -172,7 +173,7 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
}

if errorResponse.Error != "" {
return fmt.Errorf(errorResponse.Error)
return errors.New(errorResponse.Error)
}

if response.StatusCode >= http.StatusBadRequest {
Expand Down
4 changes: 1 addition & 3 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ type Options struct {

// Runner options which must be set when the model is loaded into memory
type Runner struct {
UseNUMA bool `json:"numa,omitempty"`
NumCtx int `json:"num_ctx,omitempty"`
NumBatch int `json:"num_batch,omitempty"`
NumGPU int `json:"num_gpu,omitempty"`
Expand Down Expand Up @@ -505,7 +504,7 @@ func (opts *Options) FromMap(m map[string]interface{}) error {
for key, val := range m {
opt, ok := jsonOpts[key]
if !ok {
slog.Warn("invalid option provided", "option", opt.Name)
slog.Warn("invalid option provided", "option", key)
continue
}

Expand Down Expand Up @@ -615,7 +614,6 @@ func DefaultOptions() Options {
F16KV: true,
UseMLock: false,
UseMMap: nil,
UseNUMA: false,
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"encoding/json"
"fmt"
"errors"
"math"
"testing"
"time"
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestUseMmapFormatParams(t *testing.T) {
"use_mmap": {"foo"},
},
exp: nil,
err: fmt.Errorf("invalid bool value [foo]"),
err: errors.New("invalid bool value [foo]"),
},
}

Expand Down
4 changes: 2 additions & 2 deletions app/lifecycle/getstarted_nonwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package lifecycle

import "fmt"
import "errors"

func GetStarted() error {
return fmt.Errorf("GetStarted not implemented")
return errors.New("not implemented")
}
1 change: 0 additions & 1 deletion app/lifecycle/getstarted_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func GetStarted() error {
Sys: &syscall.SysProcAttr{CreationFlags: CREATE_NEW_CONSOLE, HideWindow: false},
}
proc, err := os.StartProcess(args[0], args, attrs)

if err != nil {
return fmt.Errorf("unable to start getting started shell %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion app/lifecycle/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func InitLogging() {
// TODO - write one-line to the app.log file saying we're running in console mode to help avoid confusion
} else {
rotateLogs(AppLogFile)
logFile, err = os.OpenFile(AppLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
logFile, err = os.OpenFile(AppLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o755)
if err != nil {
slog.Error(fmt.Sprintf("failed to create server log %v", err))
return
Expand Down
2 changes: 1 addition & 1 deletion app/lifecycle/logging_nonwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ package lifecycle
import "log/slog"

func ShowLogs() {
slog.Warn("ShowLogs not yet implemented")
slog.Warn("not implemented")
}
4 changes: 2 additions & 2 deletions app/lifecycle/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestRotateLogs(t *testing.T) {
// No log exists
rotateLogs(logFile)

require.NoError(t, os.WriteFile(logFile, []byte("1"), 0644))
require.NoError(t, os.WriteFile(logFile, []byte("1"), 0o644))
assert.FileExists(t, logFile)
// First rotation
rotateLogs(logFile)
Expand All @@ -32,7 +32,7 @@ func TestRotateLogs(t *testing.T) {
assert.NoFileExists(t, logFile)

for i := 2; i <= LogRotationCount+1; i++ {
require.NoError(t, os.WriteFile(logFile, []byte(strconv.Itoa(i)), 0644))
require.NoError(t, os.WriteFile(logFile, []byte(strconv.Itoa(i)), 0o644))
assert.FileExists(t, logFile)
rotateLogs(logFile)
assert.NoFileExists(t, logFile)
Expand Down
2 changes: 1 addition & 1 deletion app/lifecycle/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func start(ctx context.Context, command string) (*exec.Cmd, error) {
}

rotateLogs(ServerLogFile)
logFile, err := os.OpenFile(ServerLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
logFile, err := os.OpenFile(ServerLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o755)
if err != nil {
return nil, fmt.Errorf("failed to create server log: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion app/lifecycle/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -46,7 +47,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
query.Add("os", runtime.GOOS)
query.Add("arch", runtime.GOARCH)
query.Add("version", version.Version)
query.Add("ts", fmt.Sprintf("%d", time.Now().Unix()))
query.Add("ts", strconv.FormatInt(time.Now().Unix(), 10))

nonce, err := auth.NewNonce(rand.Reader, 16)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/lifecycle/updater_nonwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package lifecycle

import (
"context"
"fmt"
"errors"
)

func DoUpgrade(cancel context.CancelFunc, done chan int) error {
return fmt.Errorf("DoUpgrade not yet implemented")
return errors.New("not implemented")
}
5 changes: 3 additions & 2 deletions app/lifecycle/updater_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lifecycle

import (
"context"
"errors"
"fmt"
"log/slog"
"os"
Expand All @@ -15,7 +16,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error {
return fmt.Errorf("failed to lookup downloads: %s", err)
}
if len(files) == 0 {
return fmt.Errorf("no update downloads found")
return errors.New("no update downloads found")
} else if len(files) > 1 {
// Shouldn't happen
slog.Warn(fmt.Sprintf("multiple downloads found, using first one %v", files))
Expand Down Expand Up @@ -64,7 +65,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error {
}
} else {
// TODO - some details about why it didn't start, or is this a pedantic error case?
return fmt.Errorf("installer process did not start")
return errors.New("installer process did not start")
}

// TODO should we linger for a moment and check to make sure it's actually running by checking the pid?
Expand Down
4 changes: 2 additions & 2 deletions app/tray/tray_nonwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
package tray

import (
"fmt"
"errors"

"github.com/ollama/ollama/app/tray/commontray"
)

func InitPlatformTray(icon, updateIcon []byte) (commontray.OllamaTray, error) {
return nil, fmt.Errorf("NOT IMPLEMENTED YET")
return nil, errors.New("not implemented")
}
4 changes: 1 addition & 3 deletions app/tray/wintray/eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"golang.org/x/sys/windows"
)

var (
quitOnce sync.Once
)
var quitOnce sync.Once

func (t *winTray) Run() {
nativeLoop()
Expand Down
5 changes: 3 additions & 2 deletions app/tray/wintray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
"sync"
"unsafe"

"github.com/ollama/ollama/app/tray/commontray"
"golang.org/x/sys/windows"

"github.com/ollama/ollama/app/tray/commontray"
)

// Helpful sources: https://github.com/golang/exp/blob/master/shiny/driver/internal/win32
Expand Down Expand Up @@ -414,7 +415,7 @@ func iconBytesToFilePath(iconBytes []byte) (string, error) {
iconFilePath := filepath.Join(os.TempDir(), "ollama_temp_icon_"+dataHash)

if _, err := os.Stat(iconFilePath); os.IsNotExist(err) {
if err := os.WriteFile(iconFilePath, iconBytes, 0644); err != nil {
if err := os.WriteFile(iconFilePath, iconBytes, 0o644); err != nil {
return "", err
}
}
Expand Down
3 changes: 2 additions & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"io"
"log/slog"
Expand Down Expand Up @@ -78,7 +79,7 @@ func Sign(ctx context.Context, bts []byte) (string, error) {
publicKey := ssh.MarshalAuthorizedKey(privateKey.PublicKey())
parts := bytes.Split(publicKey, []byte(" "))
if len(parts) < 2 {
return "", fmt.Errorf("malformed public key")
return "", errors.New("malformed public key")
}

signedData, err := privateKey.Sign(rand.Reader, bts)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ func checkServerHeartbeat(cmd *cobra.Command, _ []string) error {
return err
}
if err := startApp(cmd.Context(), client); err != nil {
return fmt.Errorf("could not connect to ollama app, is it running?")
return errors.New("could not connect to ollama app, is it running?")
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ func getImageData(filePath string) ([]byte, error) {
// Check if the file size exceeds 100MB
var maxSize int64 = 100 * 1024 * 1024 // 100MB in bytes
if info.Size() > maxSize {
return nil, fmt.Errorf("file size exceeds maximum limit (100MB)")
return nil, errors.New("file size exceeds maximum limit (100MB)")
}

buf = make([]byte, info.Size())
Expand Down
4 changes: 2 additions & 2 deletions cmd/start_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cmd

import (
"context"
"fmt"
"errors"
"os"
"os/exec"
"strings"
Expand All @@ -20,7 +20,7 @@ func startApp(ctx context.Context, client *api.Client) error {
return err
}
if !strings.Contains(link, "Ollama.app") {
return fmt.Errorf("could not find ollama app")
return errors.New("could not find ollama app")
}
path := strings.Split(link, "Ollama.app")
if err := exec.Command("/usr/bin/open", "-a", path[0]+"Ollama.app").Run(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/start_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package cmd

import (
"context"
"fmt"
"errors"

"github.com/ollama/ollama/api"
)

func startApp(ctx context.Context, client *api.Client) error {
return fmt.Errorf("could not connect to ollama server, run 'ollama serve' to start it")
return errors.New("could not connect to ollama server, run 'ollama serve' to start it")
}
2 changes: 1 addition & 1 deletion cmd/start_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func startApp(ctx context.Context, client *api.Client) error {
// Finally look in the path
appExe, err = exec.LookPath(AppName)
if err != nil {
return fmt.Errorf("could not locate ollama app")
return errors.New("could not locate ollama app")
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion convert/convert_llama.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"fmt"
"strings"

"github.com/ollama/ollama/llm"
"github.com/pdevine/tensor"
"github.com/pdevine/tensor/native"

"github.com/ollama/ollama/llm"
)

type llama struct {
Expand Down
Loading

0 comments on commit ca312b3

Please sign in to comment.