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
36d6081e
Commit
36d6081e
authored
Jul 31, 2023
by
Bruce MacDonald
Browse files
find symlink of mac app
parent
e72fe794
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
22 deletions
+31
-22
cmd/cmd.go
cmd/cmd.go
+31
-22
No files found.
cmd/cmd.go
View file @
36d6081e
...
...
@@ -526,34 +526,43 @@ func RunServer(_ *cobra.Command, _ []string) error {
return
server
.
Serve
(
ln
)
}
func
startMacApp
(
client
*
api
.
Client
)
error
{
link
,
err
:=
os
.
Readlink
(
"/usr/local/bin/ollama"
)
if
err
!=
nil
{
return
err
}
path
:=
strings
.
Split
(
link
,
"Ollama.app"
)
if
err
:=
exec
.
Command
(
"/usr/bin/open"
,
"-a"
,
path
[
0
]
+
"Ollama.app"
)
.
Run
();
err
!=
nil
{
return
err
}
// wait for the server to start
timeout
:=
time
.
After
(
5
*
time
.
Second
)
tick
:=
time
.
Tick
(
500
*
time
.
Millisecond
)
for
{
select
{
case
<-
timeout
:
return
errors
.
New
(
"timed out waiting for server to start"
)
case
<-
tick
:
if
err
:=
client
.
Heartbeat
(
context
.
Background
());
err
==
nil
{
return
nil
// server has started
}
}
}
}
func
checkServerHeartbeat
(
_
*
cobra
.
Command
,
_
[]
string
)
error
{
client
:=
api
.
NewClient
()
if
err
:=
client
.
Heartbeat
(
context
.
Background
());
err
!=
nil
{
if
strings
.
Contains
(
err
.
Error
(),
"connection refused"
)
{
if
runtime
.
GOOS
==
"darwin"
{
// if the mac app is available, start it
if
_
,
err
:=
os
.
Stat
(
"/Applications/Ollama.app"
);
err
==
nil
{
if
err
:=
exec
.
Command
(
"/usr/bin/open"
,
"-a"
,
"/Applications/Ollama.app"
)
.
Run
();
err
!=
nil
{
return
err
}
// wait for the server to start
timeout
:=
time
.
After
(
5
*
time
.
Second
)
tick
:=
time
.
Tick
(
500
*
time
.
Millisecond
)
for
{
select
{
case
<-
timeout
:
return
errors
.
New
(
"timed out waiting for server to start"
)
case
<-
tick
:
if
err
:=
client
.
Heartbeat
(
context
.
Background
());
err
==
nil
{
return
nil
// server has started
}
}
}
}
if
!
strings
.
Contains
(
err
.
Error
(),
"connection refused"
)
{
return
err
}
if
runtime
.
GOOS
==
"darwin"
{
if
err
:=
startMacApp
(
client
);
err
!=
nil
{
return
fmt
.
Errorf
(
"could not connect to ollama app server, run 'ollama serve' to start it"
)
}
}
else
{
return
fmt
.
Errorf
(
"could not connect to ollama server, run 'ollama serve' to start it"
)
}
return
err
}
return
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