Skip to content

feat(client): add exists() method to Client and AsyncClient#2

Open
Missing-Identity wants to merge 1 commit into
mainfrom
cursor/ollama-model-existence-dde3
Open

feat(client): add exists() method to Client and AsyncClient#2
Missing-Identity wants to merge 1 commit into
mainfrom
cursor/ollama-model-existence-dde3

Conversation

@Missing-Identity

Copy link
Copy Markdown
Owner

Summary

Adds a robust exists(model: str) -> bool method to both Client and AsyncClient.

The method delegates to show(model) and:

  • returns True when the model exists
  • returns False when a ResponseError with status code 404 is raised
  • re-raises other ResponseError and connection errors unchanged

Motivation

Checking whether a model is available currently requires calling show() and manually handling 404 responses. exists() provides a simple, idiomatic helper for this common pattern.

Changes

  • ollama/_client.py: add exists() to Client and AsyncClient
  • tests/test_client.py: add unit tests for sync/async success, 404, non-404 errors, and connection failures

Tests

pytest tests/test_client.py -k "exists" -v

All 8 new exists tests pass (plus 2 existing create_blob_exists tests matched by the filter).

Notes

Built on top of the PR ollama#684 fix for optional ShowResponse.model_info (already merged on this fork).

Open in Web Open in Cursor 

Add exists(model) that delegates to show() and returns True when the
model is present, False on ResponseError with status 404, and re-raises
other errors.

Includes unit tests for sync/async clients covering success, 404, non-404
errors, and connection failures.

Co-authored-by: Unmilan Mukherjee <Missing-Identity@users.noreply.github.com>
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