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
OpenDAS
ollama
Commits
54bb49a5
Commit
54bb49a5
authored
Aug 17, 2023
by
Jeffrey Morgan
Browse files
parse protocol for `OLLAMA_HOST`
parent
cabaada9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
13 deletions
+12
-13
api/client.go
api/client.go
+12
-13
No files found.
api/client.go
View file @
54bb49a5
...
...
@@ -10,9 +10,10 @@ import (
"net/http"
"net/url"
"os"
"strings"
)
const
DefaultHost
=
"
http://
localhost:11434"
const
DefaultHost
=
"localhost:11434"
var
(
envHost
=
os
.
Getenv
(
"OLLAMA_HOST"
)
...
...
@@ -53,23 +54,21 @@ func Host() string {
// FromEnv creates a new client using Host() as the host. An error is returns
// if the host is invalid.
func
FromEnv
()
(
*
Client
,
error
)
{
u
,
err
:=
url
.
Parse
(
Host
()
)
if
err
!=
nil
{
return
nil
,
err
h
:=
Host
()
if
!
strings
.
HasPrefix
(
h
,
"http://"
)
&&
!
strings
.
HasPrefix
(
h
,
"https://"
)
{
h
=
"http://"
+
h
}
return
&
Client
{
Base
:
*
u
},
nil
}
func
NewClient
(
hosts
...
string
)
*
Client
{
host
:=
DefaultHost
if
len
(
hosts
)
>
0
{
host
=
hosts
[
0
]
u
,
err
:=
url
.
Parse
(
h
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not parse host: %w"
,
err
)
}
return
&
Client
{
Base
:
url
.
URL
{
Scheme
:
"http"
,
Host
:
host
},
HTTP
:
http
.
Client
{},
if
u
.
Port
()
==
""
{
u
.
Host
+=
":11434"
}
return
&
Client
{
Base
:
*
u
,
HTTP
:
http
.
Client
{}},
nil
}
func
(
c
*
Client
)
do
(
ctx
context
.
Context
,
method
,
path
string
,
reqData
,
respData
any
)
error
{
...
...
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