Skip to content

Commit

Permalink
Wrap ollama.pull in try-except block
Browse files Browse the repository at this point in the history
- Encloses the `ollama.pull` call within a `try-except` block.
- Catches potential exceptions during the pull process and prints an error message.
- Improves error handling and provides more informative feedback to the user.
  • Loading branch information
yankeexe committed Dec 7, 2024
1 parent e8666ac commit 2d6c3b7
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ollama_manager/commands/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ def pull_model():

final_model = selected_model_with_tag[0].split()[0]
print(f">>> Pulling model: {final_model}")
response = ollama.pull(final_model, stream=True)
screen_padding = 100

for data in response:
out = f"Status: {data.get('status')} | Completed: {format_bytes(data.get('completed'))}/{format_bytes(data.get('total'))}"
print(f"{out:<{screen_padding}}", end='\r', flush=True)

print(f'\r{" " * screen_padding}\r') # Clear screen
print(f"✅ {final_model} model is ready for use!\n\n>>> olm run\n")
try:
response = ollama.pull(final_model, stream=True)
screen_padding = 100

for data in response:
out = f"Status: {data.get('status')} | Completed: {format_bytes(data.get('completed'))}/{format_bytes(data.get('total'))}"
print(f"{out:<{screen_padding}}", end='\r', flush=True)

print(f'\r{" " * screen_padding}\r') # Clear screen
print(f"✅ {final_model} model is ready for use!\n\n>>> olm run\n")
except Exception as e:
print(f"❌ Failed downloading {final_model}\n{str(e)}")

0 comments on commit 2d6c3b7

Please sign in to comment.