This commit is contained in:
Shaun Jackson 2026-03-06 18:05:54 -08:00 committed by GitHub
commit 85332c4c3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View File

@ -57,3 +57,4 @@ show = _client.show
ps = _client.ps
web_search = _client.web_search
web_fetch = _client.web_fetch
ping = _client.ping

View File

@ -670,6 +670,10 @@ class Client(BaseClient):
'GET',
'/api/ps',
)
def ping(self) -> str:
r = self._request_raw('GET', '/')
return r.text
def web_search(self, query: str, max_results: int = 3) -> WebSearchResponse:
"""
@ -1305,6 +1309,10 @@ class AsyncClient(BaseClient):
).model_dump(exclude_none=True),
)
async def ping(self) -> str:
r = await self._request_raw('GET', '/')
return r.text
async def ps(self) -> ProcessResponse:
return await self._request(
ProcessResponse,

View File

@ -879,6 +879,19 @@ def test_client_copy(httpserver: HTTPServer):
assert response['status'] == 'success'
def test_client_ping(httpserver: HTTPServer):
httpserver.expect_ordered_request('/', method='GET').respond_with_response(Response('Ollama is running', status=200))
client = Client(httpserver.url_for('/'))
response = client.ping()
assert response == 'Ollama is running'
def test_client_ping_connection_error():
client = Client('http://localhost:1')
with pytest.raises(ConnectionError, match=CONNECTION_ERROR_MESSAGE):
client.ping()
async def test_async_client_chat(httpserver: HTTPServer):
httpserver.expect_ordered_request(
'/api/chat',
@ -1256,6 +1269,19 @@ async def test_async_client_copy(httpserver: HTTPServer):
assert response['status'] == 'success'
async def test_async_client_ping(httpserver: HTTPServer):
httpserver.expect_ordered_request('/', method='GET').respond_with_response(Response('Ollama is running', status=200))
client = AsyncClient(httpserver.url_for('/'))
response = await client.ping()
assert response == 'Ollama is running'
async def test_async_client_ping_connection_error():
client = AsyncClient('http://localhost:1')
with pytest.raises(ConnectionError, match=CONNECTION_ERROR_MESSAGE):
await client.ping()
def test_headers():
client = Client()
assert client._client.headers['content-type'] == 'application/json'