Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
orangecat
ollama
Commits
50792821
"test/vscode:/vscode.git/clone" did not exist on "d5eadbdc28a751aba10b57cbad52f90dbbf64938"
Commit
50792821
authored
Jul 06, 2023
by
Michael Yang
Committed by
Jeffrey Morgan
Jul 06, 2023
Browse files
tcp socket
parent
3c3c09a5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
48 deletions
+3
-48
api/client.go
api/client.go
+1
-14
cmd/cmd.go
cmd/cmd.go
+2
-34
No files found.
api/client.go
View file @
50792821
...
@@ -11,12 +11,8 @@ import (
...
@@ -11,12 +11,8 @@ import (
)
)
type
Client
struct
{
type
Client
struct
{
Name
string
Version
string
URL
string
URL
string
HTTP
http
.
Client
HTTP
http
.
Client
Headers
http
.
Header
PrivateKey
[]
byte
}
}
func
checkError
(
resp
*
http
.
Response
,
body
[]
byte
)
error
{
func
checkError
(
resp
*
http
.
Response
,
body
[]
byte
)
error
{
...
@@ -26,8 +22,7 @@ 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
)}
apiError
:=
Error
{
Code
:
int32
(
resp
.
StatusCode
)}
err
:=
json
.
Unmarshal
(
body
,
&
apiError
)
if
err
:=
json
.
Unmarshal
(
body
,
&
apiError
);
err
!=
nil
{
if
err
!=
nil
{
// Use the full body as the message if we fail to decode a response.
// Use the full body as the message if we fail to decode a response.
apiError
.
Message
=
string
(
body
)
apiError
.
Message
=
string
(
body
)
}
}
...
@@ -57,10 +52,6 @@ func (c *Client) stream(ctx context.Context, method string, path string, reqData
...
@@ -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
(
"Content-Type"
,
"application/json"
)
req
.
Header
.
Set
(
"Accept"
,
"application/json"
)
req
.
Header
.
Set
(
"Accept"
,
"application/json"
)
for
k
,
v
:=
range
c
.
Headers
{
req
.
Header
[
k
]
=
v
}
res
,
err
:=
c
.
HTTP
.
Do
(
req
)
res
,
err
:=
c
.
HTTP
.
Do
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -103,10 +94,6 @@ func (c *Client) do(ctx context.Context, method string, path string, reqData any
...
@@ -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
(
"Content-Type"
,
"application/json"
)
req
.
Header
.
Set
(
"Accept"
,
"application/json"
)
req
.
Header
.
Set
(
"Accept"
,
"application/json"
)
for
k
,
v
:=
range
c
.
Headers
{
req
.
Header
[
k
]
=
v
}
respObj
,
err
:=
c
.
HTTP
.
Do
(
req
)
respObj
,
err
:=
c
.
HTTP
.
Do
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
cmd/cmd.go
View file @
50792821
...
@@ -5,10 +5,8 @@ import (
...
@@ -5,10 +5,8 @@ import (
"fmt"
"fmt"
"log"
"log"
"net"
"net"
"net/http"
"os"
"os"
"path"
"path"
"time"
"github.com/jmorganca/ollama/api"
"github.com/jmorganca/ollama/api"
"github.com/jmorganca/ollama/server"
"github.com/jmorganca/ollama/server"
...
@@ -40,47 +38,17 @@ func run(model string) error {
...
@@ -40,47 +38,17 @@ func run(model string) error {
}
}
func
serve
()
error
{
func
serve
()
error
{
sp
:=
path
.
Join
(
cacheDir
(),
"ollama.sock"
)
ln
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:11434"
)
if
err
:=
os
.
RemoveAll
(
sp
);
err
!=
nil
{
return
err
}
ln
,
err
:=
net
.
Listen
(
"unix"
,
sp
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
os
.
Chmod
(
sp
,
0
o700
);
err
!=
nil
{
return
err
}
return
server
.
Serve
(
ln
)
return
server
.
Serve
(
ln
)
}
}
func
NewAPIClient
()
(
*
api
.
Client
,
error
)
{
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
{
return
&
api
.
Client
{
URL
:
"http://localhost"
,
URL
:
"http://localhost:11434"
,
HTTP
:
http
.
Client
{
Transport
:
&
http
.
Transport
{
DialContext
:
func
(
ctx
context
.
Context
,
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
dialer
.
DialContext
(
ctx
,
"unix"
,
socket
)
},
},
},
},
nil
},
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment