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
142cbb72
Unverified
Commit
142cbb72
authored
Aug 30, 2024
by
Michael Yang
Committed by
GitHub
Aug 30, 2024
Browse files
Merge pull request #6482 from ollama/mxyng/client-path
passthrough OLLAMA_HOST path to client
parents
9468c682
386af6c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
30 deletions
+27
-30
envconfig/config.go
envconfig/config.go
+3
-7
envconfig/config_test.go
envconfig/config_test.go
+24
-23
No files found.
envconfig/config.go
View file @
142cbb72
...
...
@@ -30,9 +30,7 @@ func Host() *url.URL {
defaultPort
=
"443"
}
// trim trailing slashes
hostport
=
strings
.
TrimRight
(
hostport
,
"/"
)
hostport
,
path
,
_
:=
strings
.
Cut
(
hostport
,
"/"
)
host
,
port
,
err
:=
net
.
SplitHostPort
(
hostport
)
if
err
!=
nil
{
host
,
port
=
"127.0.0.1"
,
defaultPort
...
...
@@ -45,15 +43,13 @@ func Host() *url.URL {
if
n
,
err
:=
strconv
.
ParseInt
(
port
,
10
,
32
);
err
!=
nil
||
n
>
65535
||
n
<
0
{
slog
.
Warn
(
"invalid port, using default"
,
"port"
,
port
,
"default"
,
defaultPort
)
return
&
url
.
URL
{
Scheme
:
scheme
,
Host
:
net
.
JoinHostPort
(
host
,
defaultPort
),
}
port
=
defaultPort
}
return
&
url
.
URL
{
Scheme
:
scheme
,
Host
:
net
.
JoinHostPort
(
host
,
port
),
Path
:
path
,
}
}
...
...
envconfig/config_test.go
View file @
142cbb72
...
...
@@ -13,34 +13,35 @@ func TestHost(t *testing.T) {
value
string
expect
string
}{
"empty"
:
{
""
,
"127.0.0.1:11434"
},
"only address"
:
{
"1.2.3.4"
,
"1.2.3.4:11434"
},
"only port"
:
{
":1234"
,
":1234"
},
"address and port"
:
{
"1.2.3.4:1234"
,
"1.2.3.4:1234"
},
"hostname"
:
{
"example.com"
,
"example.com:11434"
},
"hostname and port"
:
{
"example.com:1234"
,
"example.com:1234"
},
"zero port"
:
{
":0"
,
":0"
},
"too large port"
:
{
":66000"
,
":11434"
},
"too small port"
:
{
":-1"
,
":11434"
},
"ipv6 localhost"
:
{
"[::1]"
,
"[::1]:11434"
},
"ipv6 world open"
:
{
"[::]"
,
"[::]:11434"
},
"ipv6 no brackets"
:
{
"::1"
,
"[::1]:11434"
},
"ipv6 + port"
:
{
"[::1]:1337"
,
"[::1]:1337"
},
"extra space"
:
{
" 1.2.3.4 "
,
"1.2.3.4:11434"
},
"extra quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"1.2.3.4:11434"
},
"extra space+quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"1.2.3.4:11434"
},
"extra single quotes"
:
{
"'1.2.3.4'"
,
"1.2.3.4:11434"
},
"http"
:
{
"http://1.2.3.4"
,
"1.2.3.4:80"
},
"http port"
:
{
"http://1.2.3.4:4321"
,
"1.2.3.4:4321"
},
"https"
:
{
"https://1.2.3.4"
,
"1.2.3.4:443"
},
"https port"
:
{
"https://1.2.3.4:4321"
,
"1.2.3.4:4321"
},
"empty"
:
{
""
,
"http://127.0.0.1:11434"
},
"only address"
:
{
"1.2.3.4"
,
"http://1.2.3.4:11434"
},
"only port"
:
{
":1234"
,
"http://:1234"
},
"address and port"
:
{
"1.2.3.4:1234"
,
"http://1.2.3.4:1234"
},
"hostname"
:
{
"example.com"
,
"http://example.com:11434"
},
"hostname and port"
:
{
"example.com:1234"
,
"http://example.com:1234"
},
"zero port"
:
{
":0"
,
"http://:0"
},
"too large port"
:
{
":66000"
,
"http://:11434"
},
"too small port"
:
{
":-1"
,
"http://:11434"
},
"ipv6 localhost"
:
{
"[::1]"
,
"http://[::1]:11434"
},
"ipv6 world open"
:
{
"[::]"
,
"http://[::]:11434"
},
"ipv6 no brackets"
:
{
"::1"
,
"http://[::1]:11434"
},
"ipv6 + port"
:
{
"[::1]:1337"
,
"http://[::1]:1337"
},
"extra space"
:
{
" 1.2.3.4 "
,
"http://1.2.3.4:11434"
},
"extra quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"http://1.2.3.4:11434"
},
"extra space+quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"http://1.2.3.4:11434"
},
"extra single quotes"
:
{
"'1.2.3.4'"
,
"http://1.2.3.4:11434"
},
"http"
:
{
"http://1.2.3.4"
,
"http://1.2.3.4:80"
},
"http port"
:
{
"http://1.2.3.4:4321"
,
"http://1.2.3.4:4321"
},
"https"
:
{
"https://1.2.3.4"
,
"https://1.2.3.4:443"
},
"https port"
:
{
"https://1.2.3.4:4321"
,
"https://1.2.3.4:4321"
},
"proxy path"
:
{
"https://example.com/ollama"
,
"https://example.com:443/ollama"
},
}
for
name
,
tt
:=
range
cases
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
t
.
Setenv
(
"OLLAMA_HOST"
,
tt
.
value
)
if
host
:=
Host
();
host
.
Host
!=
tt
.
expect
{
t
.
Errorf
(
"%s: expected %s, got %s"
,
name
,
tt
.
expect
,
host
.
Host
)
if
host
:=
Host
();
host
.
String
()
!=
tt
.
expect
{
t
.
Errorf
(
"%s: expected %s, got %s"
,
name
,
tt
.
expect
,
host
.
String
()
)
}
})
}
...
...
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