Michael Yang 1 rok temu
rodzic
commit
5079282120
2 zmienionych plików z 3 dodań i 48 usunięć
  1. 1 14
      api/client.go
  2. 2 34
      cmd/cmd.go

+ 1 - 14
api/client.go

@@ -11,12 +11,8 @@ import (
 )
 
 type Client struct {
-	Name       string
-	Version    string
 	URL        string
 	HTTP       http.Client
-	Headers    http.Header
-	PrivateKey []byte
 }
 
 func checkError(resp *http.Response, body []byte) error {
@@ -26,8 +22,7 @@ func checkError(resp *http.Response, body []byte) error {
 
 	apiError := Error{Code: int32(resp.StatusCode)}
 
-	err := json.Unmarshal(body, &apiError)
-	if err != nil {
+	if err := json.Unmarshal(body, &apiError); err != nil {
 		// Use the full body as the message if we fail to decode a response.
 		apiError.Message = string(body)
 	}
@@ -57,10 +52,6 @@ func (c *Client) stream(ctx context.Context, method string, path string, reqData
 	req.Header.Set("Content-Type", "application/json")
 	req.Header.Set("Accept", "application/json")
 
-	for k, v := range c.Headers {
-		req.Header[k] = v
-	}
-
 	res, err := c.HTTP.Do(req)
 	if err != nil {
 		return err
@@ -103,10 +94,6 @@ func (c *Client) do(ctx context.Context, method string, path string, reqData any
 	req.Header.Set("Content-Type", "application/json")
 	req.Header.Set("Accept", "application/json")
 
-	for k, v := range c.Headers {
-		req.Header[k] = v
-	}
-
 	respObj, err := c.HTTP.Do(req)
 	if err != nil {
 		return err

+ 2 - 34
cmd/cmd.go

@@ -5,10 +5,8 @@ import (
 	"fmt"
 	"log"
 	"net"
-	"net/http"
 	"os"
 	"path"
-	"time"
 
 	"github.com/jmorganca/ollama/api"
 	"github.com/jmorganca/ollama/server"
@@ -40,47 +38,17 @@ func run(model string) error {
 }
 
 func serve() error {
-	sp := path.Join(cacheDir(), "ollama.sock")
-
-	if err := os.RemoveAll(sp); err != nil {
-		return err
-	}
-
-	ln, err := net.Listen("unix", sp)
+	ln, err := net.Listen("tcp", "127.0.0.1:11434")
 	if err != nil {
 		return err
 	}
 
-	if err := os.Chmod(sp, 0o700); err != nil {
-		return err
-	}
-
 	return server.Serve(ln)
 }
 
 func NewAPIClient() (*api.Client, error) {
-	var err error
-
-	home, err := os.UserHomeDir()
-	if err != nil {
-		return nil, err
-	}
-
-	socket := path.Join(home, ".ollama", "ollama.sock")
-
-	dialer := &net.Dialer{
-		Timeout: 10 * time.Second,
-	}
-
 	return &api.Client{
-		URL: "http://localhost",
-		HTTP: http.Client{
-			Transport: &http.Transport{
-				DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
-					return dialer.DialContext(ctx, "unix", socket)
-				},
-			},
-		},
+		URL: "http://localhost:11434",
 	}, nil
 }