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
ebec1c61
You need to sign in or sign up before continuing.
Commit
ebec1c61
authored
Jun 23, 2023
by
Bruce MacDonald
Browse files
load and unload model endpoints
parent
b97b9504
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
server/server.py
server/server.py
+33
-1
No files found.
server/server.py
View file @
ebec1c61
...
@@ -11,6 +11,37 @@ CORS(app) # enable CORS for all routes
...
@@ -11,6 +11,37 @@ CORS(app) # enable CORS for all routes
llms
=
{}
llms
=
{}
@
app
.
route
(
"/load"
,
methods
=
[
"POST"
])
def
load
():
data
=
request
.
get_json
()
model
=
data
.
get
(
"model"
)
if
not
model
:
return
Response
(
"Model is required"
,
status
=
400
)
if
not
os
.
path
.
exists
(
f
"../models/
{
model
}
.bin"
):
return
{
"error"
:
"The model does not exist."
},
400
if
model
not
in
llms
:
llms
[
model
]
=
Llama
(
model_path
=
f
"../models/
{
model
}
.bin"
)
return
Response
(
status
=
204
)
@
app
.
route
(
"/unload"
,
methods
=
[
"POST"
])
def
unload
():
data
=
request
.
get_json
()
model
=
data
.
get
(
"model"
)
if
not
model
:
return
Response
(
"Model is required"
,
status
=
400
)
if
not
os
.
path
.
exists
(
f
"../models/
{
model
}
.bin"
):
return
{
"error"
:
"The model does not exist."
},
400
llms
.
pop
(
model
,
None
)
return
Response
(
status
=
204
)
@
app
.
route
(
"/generate"
,
methods
=
[
"POST"
])
@
app
.
route
(
"/generate"
,
methods
=
[
"POST"
])
def
generate
():
def
generate
():
data
=
request
.
get_json
()
data
=
request
.
get_json
()
...
@@ -22,9 +53,10 @@ def generate():
...
@@ -22,9 +53,10 @@ def generate():
if
not
prompt
:
if
not
prompt
:
return
Response
(
"Prompt is required"
,
status
=
400
)
return
Response
(
"Prompt is required"
,
status
=
400
)
if
not
os
.
path
.
exists
(
f
"../models/
{
model
}
.bin"
):
if
not
os
.
path
.
exists
(
f
"../models/
{
model
}
.bin"
):
return
{
"error"
:
"The model
file
does not exist."
},
400
return
{
"error"
:
"The model does not exist."
},
400
if
model
not
in
llms
:
if
model
not
in
llms
:
# auto load
llms
[
model
]
=
Llama
(
model_path
=
f
"../models/
{
model
}
.bin"
)
llms
[
model
]
=
Llama
(
model_path
=
f
"../models/
{
model
}
.bin"
)
def
stream_response
():
def
stream_response
():
...
...
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