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
567e74e7
Unverified
Commit
567e74e7
authored
Jul 14, 2023
by
Michael Yang
Committed by
GitHub
Jul 14, 2023
Browse files
Merge pull request #81 from jmorganca/fix-race-2
fix race
parents
965f9ad0
5ade3db0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
31 deletions
+26
-31
server/routes.go
server/routes.go
+26
-31
No files found.
server/routes.go
View file @
567e74e7
...
@@ -58,9 +58,6 @@ func generate(c *gin.Context) {
...
@@ -58,9 +58,6 @@ func generate(c *gin.Context) {
req
.
Model
=
path
.
Join
(
cacheDir
(),
"models"
,
req
.
Model
+
".bin"
)
req
.
Model
=
path
.
Join
(
cacheDir
(),
"models"
,
req
.
Model
+
".bin"
)
}
}
ch
:=
make
(
chan
any
)
go
stream
(
c
,
ch
)
templateNames
:=
make
([]
string
,
0
,
len
(
templates
.
Templates
()))
templateNames
:=
make
([]
string
,
0
,
len
(
templates
.
Templates
()))
for
_
,
template
:=
range
templates
.
Templates
()
{
for
_
,
template
:=
range
templates
.
Templates
()
{
templateNames
=
append
(
templateNames
,
template
.
Name
())
templateNames
=
append
(
templateNames
,
template
.
Name
())
...
@@ -84,7 +81,10 @@ func generate(c *gin.Context) {
...
@@ -84,7 +81,10 @@ func generate(c *gin.Context) {
}
}
defer
llm
.
Close
()
defer
llm
.
Close
()
fn
:=
func
(
r
api
.
GenerateResponse
)
{
ch
:=
make
(
chan
any
)
go
func
()
{
defer
close
(
ch
)
llm
.
Predict
(
req
.
Context
,
req
.
Prompt
,
func
(
r
api
.
GenerateResponse
)
{
r
.
Model
=
req
.
Model
r
.
Model
=
req
.
Model
r
.
CreatedAt
=
time
.
Now
()
.
UTC
()
r
.
CreatedAt
=
time
.
Now
()
.
UTC
()
if
r
.
Done
{
if
r
.
Done
{
...
@@ -92,13 +92,10 @@ func generate(c *gin.Context) {
...
@@ -92,13 +92,10 @@ func generate(c *gin.Context) {
}
}
ch
<-
r
ch
<-
r
}
})
}()
if
err
:=
llm
.
Predict
(
req
.
Context
,
req
.
Prompt
,
fn
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
streamResponse
(
c
,
ch
)
}
}
func
pull
(
c
*
gin
.
Context
)
{
func
pull
(
c
*
gin
.
Context
)
{
...
@@ -133,20 +130,18 @@ func pull(c *gin.Context) {
...
@@ -133,20 +130,18 @@ func pull(c *gin.Context) {
}
}
ch
:=
make
(
chan
any
)
ch
:=
make
(
chan
any
)
go
stream
(
c
,
ch
)
go
func
()
{
defer
close
(
ch
)
fn
:=
func
(
total
,
completed
int64
)
{
saveModel
(
remote
,
func
(
total
,
completed
int64
)
{
ch
<-
api
.
PullProgress
{
ch
<-
api
.
PullProgress
{
Total
:
total
,
Total
:
total
,
Completed
:
completed
,
Completed
:
completed
,
Percent
:
float64
(
completed
)
/
float64
(
total
)
*
100
,
Percent
:
float64
(
completed
)
/
float64
(
total
)
*
100
,
}
}
}
})
}()
if
err
:=
saveModel
(
remote
,
fn
);
err
!=
nil
{
streamResponse
(
c
,
ch
)
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
}
}
func
Serve
(
ln
net
.
Listener
)
error
{
func
Serve
(
ln
net
.
Listener
)
error
{
...
@@ -179,7 +174,7 @@ func matchRankOne(source string, targets []string) (bestMatch string, bestRank i
...
@@ -179,7 +174,7 @@ func matchRankOne(source string, targets []string) (bestMatch string, bestRank i
return
return
}
}
func
stream
(
c
*
gin
.
Context
,
ch
chan
any
)
{
func
stream
Response
(
c
*
gin
.
Context
,
ch
chan
any
)
{
c
.
Stream
(
func
(
w
io
.
Writer
)
bool
{
c
.
Stream
(
func
(
w
io
.
Writer
)
bool
{
val
,
ok
:=
<-
ch
val
,
ok
:=
<-
ch
if
!
ok
{
if
!
ok
{
...
...
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