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
b5c54f5a
Commit
b5c54f5a
authored
Jun 28, 2023
by
Bruce MacDonald
Browse files
resume pull download
parent
50f5adb0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
18 deletions
+31
-18
ollama/model.py
ollama/model.py
+31
-18
No files found.
ollama/model.py
View file @
b5c54f5a
...
@@ -45,30 +45,43 @@ def pull(remote, models_home=".", *args, **kwargs):
...
@@ -45,30 +45,43 @@ def pull(remote, models_home=".", *args, **kwargs):
json_response
=
response
.
json
()
json_response
=
response
.
json
()
# get the last bin file we find, this is probably the most up to date
download_url
=
None
for
file_info
in
json_response
:
for
file_info
in
json_response
:
if
file_info
.
get
(
"type"
)
==
"file"
and
file_info
.
get
(
"path"
).
endswith
(
".bin"
):
if
file_info
.
get
(
"type"
)
==
"file"
and
file_info
.
get
(
"path"
).
endswith
(
".bin"
):
f_path
=
file_info
.
get
(
"path"
)
f_path
=
file_info
.
get
(
"path"
)
download_url
=
f
"https://huggingface.co/
{
model
}
/resolve/
{
branch
}
/
{
f_path
}
"
download_url
=
f
"https://huggingface.co/
{
model
}
/resolve/
{
branch
}
/
{
f_path
}
"
local_filename
=
os
.
path
.
join
(
models_home
,
os
.
path
.
basename
(
model
))
+
".bin"
if
os
.
path
.
exists
(
local_filename
):
if
download_url
is
None
:
# TODO: check if the file is the same SHA
raise
Exception
(
"No model found"
)
break
response
=
requests
.
get
(
download_url
,
stream
=
True
)
local_filename
=
os
.
path
.
join
(
models_home
,
os
.
path
.
basename
(
model
))
+
".bin"
response
.
raise_for_status
()
# Raises stored HTTPError, if one occurred
total_size
=
int
(
response
.
headers
.
get
(
"content-length"
,
0
))
# Check if file already exists
if
os
.
path
.
exists
(
local_filename
):
# TODO: check if the file is the same SHA
first_byte
=
os
.
path
.
getsize
(
local_filename
)
else
:
first_byte
=
0
# If file size is non-zero, resume download
if
first_byte
!=
0
:
header
=
{
"Range"
:
f
"bytes=
{
first_byte
}
-"
}
else
:
header
=
{}
with
open
(
local_filename
,
"wb"
)
as
file
,
tqdm
(
response
=
requests
.
get
(
download_url
,
headers
=
header
,
stream
=
True
)
desc
=
local_filename
,
response
.
raise_for_status
()
# Raises stored HTTPError, if one occurred
total
=
total_size
,
unit
=
"iB"
,
unit_scale
=
True
,
unit_divisor
=
1024
,
)
as
bar
:
for
data
in
response
.
iter_content
(
chunk_size
=
1024
):
size
=
file
.
write
(
data
)
bar
.
update
(
size
)
break
# Stop after downloading the first .bin file
total_size
=
int
(
response
.
headers
.
get
(
"content-length"
,
0
))
with
open
(
local_filename
,
"ab"
if
first_byte
else
"wb"
)
as
file
,
tqdm
(
total
=
total_size
,
unit
=
"iB"
,
unit_scale
=
True
,
unit_divisor
=
1024
,
initial
=
first_byte
,
)
as
bar
:
for
data
in
response
.
iter_content
(
chunk_size
=
1024
):
size
=
file
.
write
(
data
)
bar
.
update
(
size
)
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