commit
d061bc2dde
39
cmd/cmd.go
39
cmd/cmd.go
@ -11,6 +11,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -98,22 +99,21 @@ func RunHandler(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
models, err := client.List(context.Background())
|
name := args[0]
|
||||||
|
// check if the model exists on the server
|
||||||
|
_, err = client.Show(context.Background(), &api.ShowRequest{Name: name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
var statusError api.StatusError
|
||||||
}
|
switch {
|
||||||
|
case errors.As(err, &statusError) && statusError.StatusCode == http.StatusNotFound:
|
||||||
canonicalModelPath := server.ParseModelPath(args[0])
|
if err := PullHandler(cmd, args); err != nil {
|
||||||
for _, model := range models.Models {
|
return err
|
||||||
if model.Name == canonicalModelPath.GetShortTagname() {
|
}
|
||||||
return RunGenerate(cmd, args)
|
case err != nil:
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := PullHandler(cmd, args); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return RunGenerate(cmd, args)
|
return RunGenerate(cmd, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,21 +731,6 @@ func RunServer(cmd *cobra.Command, _ []string) error {
|
|||||||
origins = strings.Split(o, ",")
|
origins = strings.Split(o, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
if noprune := os.Getenv("OLLAMA_NOPRUNE"); noprune == "" {
|
|
||||||
if err := server.PruneLayers(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
manifestsPath, err := server.GetManifestPath()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := server.PruneDirectory(manifestsPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return server.Serve(ln, origins)
|
return server.Serve(ln, origins)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ python convert.py <path to model directory>
|
|||||||
python convert-falcon-hf-to-gguf.py <path to model directory>
|
python convert-falcon-hf-to-gguf.py <path to model directory>
|
||||||
|
|
||||||
# GPTNeoXForCausalLM
|
# GPTNeoXForCausalLM
|
||||||
python convert-falcon-hf-to-gguf.py <path to model directory>
|
python convert-gptneox-hf-to-gguf.py <path to model directory>
|
||||||
|
|
||||||
# GPTBigCodeForCausalLM
|
# GPTBigCodeForCausalLM
|
||||||
python convert-starcoder-hf-to-gguf.py <path to model directory>
|
python convert-starcoder-hf-to-gguf.py <path to model directory>
|
||||||
|
@ -2,6 +2,7 @@ package readline
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/emirpasic/gods/lists/arraylist"
|
"github.com/emirpasic/gods/lists/arraylist"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
@ -17,7 +18,8 @@ type Buffer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewBuffer(prompt *Prompt) (*Buffer, error) {
|
func NewBuffer(prompt *Prompt) (*Buffer, error) {
|
||||||
width, height, err := term.GetSize(0)
|
fd := int(os.Stdout.Fd())
|
||||||
|
width, height, err := term.GetSize(fd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error getting size:", err)
|
fmt.Println("Error getting size:", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -51,11 +51,12 @@ func (i *Instance) Readline() (string, error) {
|
|||||||
}
|
}
|
||||||
fmt.Print(prompt)
|
fmt.Print(prompt)
|
||||||
|
|
||||||
termios, err := SetRawMode(syscall.Stdin)
|
fd := int(syscall.Stdin)
|
||||||
|
termios, err := SetRawMode(fd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer UnsetRawMode(syscall.Stdin, termios)
|
defer UnsetRawMode(fd, termios)
|
||||||
|
|
||||||
buf, _ := NewBuffer(i.Prompt)
|
buf, _ := NewBuffer(i.Prompt)
|
||||||
|
|
||||||
|
62
readline/term_windows.go
Normal file
62
readline/term_windows.go
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
package readline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
enableLineInput = 2
|
||||||
|
enableWindowInput = 8
|
||||||
|
enableMouseInput = 16
|
||||||
|
enableInsertMode = 32
|
||||||
|
enableQuickEditMode = 64
|
||||||
|
enableExtendedFlags = 128
|
||||||
|
enableProcessedOutput = 1
|
||||||
|
enableWrapAtEolOutput = 2
|
||||||
|
enableAutoPosition = 256 // Cursor position is not affected by writing data to the console.
|
||||||
|
enableEchoInput = 4 // Characters are written to the console as they're read.
|
||||||
|
enableProcessedInput = 1 // Enables input processing (like recognizing Ctrl+C).
|
||||||
|
)
|
||||||
|
|
||||||
|
var kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||||
|
|
||||||
|
var (
|
||||||
|
procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
|
||||||
|
procSetConsoleMode = kernel32.NewProc("SetConsoleMode")
|
||||||
|
)
|
||||||
|
|
||||||
|
type State struct {
|
||||||
|
mode uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsTerminal checks if the given file descriptor is associated with a terminal
|
||||||
|
func IsTerminal(fd int) bool {
|
||||||
|
var st uint32
|
||||||
|
r, _, e := syscall.SyscallN(procGetConsoleMode.Addr(), uintptr(fd), uintptr(unsafe.Pointer(&st)), 0)
|
||||||
|
// if the call succeeds and doesn't produce an error, it's a terminal
|
||||||
|
return r != 0 && e == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetRawMode(fd int) (*State, error) {
|
||||||
|
var st uint32
|
||||||
|
// retrieve the current mode of the terminal
|
||||||
|
_, _, e := syscall.SyscallN(procGetConsoleMode.Addr(), uintptr(fd), uintptr(unsafe.Pointer(&st)), 0)
|
||||||
|
if e != 0 {
|
||||||
|
return nil, error(e)
|
||||||
|
}
|
||||||
|
// modify the mode to set it to raw
|
||||||
|
raw := st &^ (enableEchoInput | enableProcessedInput | enableLineInput | enableProcessedOutput)
|
||||||
|
// apply the new mode to the terminal
|
||||||
|
_, _, e = syscall.SyscallN(procSetConsoleMode.Addr(), uintptr(fd), uintptr(raw), 0)
|
||||||
|
if e != 0 {
|
||||||
|
return nil, error(e)
|
||||||
|
}
|
||||||
|
// return the original state so that it can be restored later
|
||||||
|
return &State{st}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnsetRawMode(fd int, state *State) error {
|
||||||
|
_, _, err := syscall.SyscallN(procSetConsoleMode.Addr(), uintptr(fd), uintptr(state.mode), 0)
|
||||||
|
return err
|
||||||
|
}
|
@ -614,6 +614,22 @@ var defaultAllowOrigins = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Serve(ln net.Listener, allowOrigins []string) error {
|
func Serve(ln net.Listener, allowOrigins []string) error {
|
||||||
|
if noprune := os.Getenv("OLLAMA_NOPRUNE"); noprune == "" {
|
||||||
|
// clean up unused layers and manifests
|
||||||
|
if err := PruneLayers(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
manifestsPath, err := GetManifestPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := PruneDirectory(manifestsPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config := cors.DefaultConfig()
|
config := cors.DefaultConfig()
|
||||||
config.AllowWildcard = true
|
config.AllowWildcard = true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user