Skip to content

feat: add client.exists() to check if a model is available locally#649

Open
CyberRaccoonTeam wants to merge 1 commit intoollama:mainfrom
CyberRaccoonTeam:feat/client-exists-640
Open

feat: add client.exists() to check if a model is available locally#649
CyberRaccoonTeam wants to merge 1 commit intoollama:mainfrom
CyberRaccoonTeam:feat/client-exists-640

Conversation

@CyberRaccoonTeam
Copy link
Copy Markdown

Summary

Adds a convenience method client.exists(model_name) to check if a model is available locally without raising an exception.

Problem

Currently, checking if a model exists requires either calling client.show() and catching an exception, or listing all models and filtering. This is verbose and error-prone.

Solution

# Before
try:
    client.show("llama3.2")
    exists = True
except ResponseError:
    exists = False

# After
exists = client.exists("llama3.2")  # Returns True/False

Changes

  • Added exists() method to Client class
  • Returns True if model is available locally, False otherwise
  • Handles ResponseError internally
  • Added tests for the new method

Testing

  • ✅ Test with existing model returns True
  • ✅ Test with non-existing model returns False
  • ✅ All existing tests pass

Implements ollama#640 — adds exists() method to Client and AsyncClient that
wraps list() to check if a specific model is pulled locally.

Usage:
  client.exists('llama3.1:8b')  # True or False

Also exposed as top-level ollama.exists() convenience function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant