From d5316d023a40c38c40aee5e98e2b9a01dbeb949f Mon Sep 17 00:00:00 2001 From: royjhan <65097070+royjhan@users.noreply.github.com> Date: Wed, 5 Jun 2024 11:12:32 -0700 Subject: [PATCH] Python API PS (#177) * Python API PS * PS Rename * Readme --- README.md | 6 ++++++ ollama/__init__.py | 2 ++ ollama/_client.py | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 0ef5005..49ab183 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,12 @@ ollama.push('user/llama3') ollama.embeddings(model='llama3', prompt='The sky is blue because of rayleigh scattering') ``` +### Ps + +```python +ollama.ps() +``` + ## Custom client A custom client can be created with the following fields: diff --git a/ollama/__init__.py b/ollama/__init__.py index 048bb14..80b0858 100644 --- a/ollama/__init__.py +++ b/ollama/__init__.py @@ -29,6 +29,7 @@ __all__ = [ 'list', 'copy', 'show', + 'ps', ] _client = Client() @@ -43,3 +44,4 @@ delete = _client.delete list = _client.list copy = _client.copy show = _client.show +ps = _client.ps diff --git a/ollama/_client.py b/ollama/_client.py index 6e40081..f38cab9 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -336,6 +336,9 @@ class Client(BaseClient): def show(self, model: str) -> Mapping[str, Any]: return self._request('POST', '/api/show', json={'name': model}).json() + def ps(self) -> Mapping[str, Any]: + return self._request('GET', '/api/ps').json() + class AsyncClient(BaseClient): def __init__(self, host: Optional[str] = None, **kwargs) -> None: @@ -629,6 +632,10 @@ class AsyncClient(BaseClient): response = await self._request('POST', '/api/show', json={'name': model}) return response.json() + async def ps(self) -> Mapping[str, Any]: + response = await self._request('GET', '/api/ps') + return response.json() + def _encode_image(image) -> str: """