mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-03 12:52:35 +00:00
Add ping method for health endpoint
This commit is contained in:
@@ -57,3 +57,4 @@ show = _client.show
|
|||||||
ps = _client.ps
|
ps = _client.ps
|
||||||
web_search = _client.web_search
|
web_search = _client.web_search
|
||||||
web_fetch = _client.web_fetch
|
web_fetch = _client.web_fetch
|
||||||
|
ping = _client.ping
|
||||||
|
|||||||
@@ -671,6 +671,10 @@ class Client(BaseClient):
|
|||||||
'/api/ps',
|
'/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:
|
def web_search(self, query: str, max_results: int = 3) -> WebSearchResponse:
|
||||||
"""
|
"""
|
||||||
Performs a web search
|
Performs a web search
|
||||||
@@ -1305,6 +1309,10 @@ class AsyncClient(BaseClient):
|
|||||||
).model_dump(exclude_none=True),
|
).model_dump(exclude_none=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def ping(self) -> str:
|
||||||
|
r = await self._request_raw('GET', '/')
|
||||||
|
return r.text
|
||||||
|
|
||||||
async def ps(self) -> ProcessResponse:
|
async def ps(self) -> ProcessResponse:
|
||||||
return await self._request(
|
return await self._request(
|
||||||
ProcessResponse,
|
ProcessResponse,
|
||||||
|
|||||||
@@ -879,6 +879,19 @@ def test_client_copy(httpserver: HTTPServer):
|
|||||||
assert response['status'] == 'success'
|
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):
|
async def test_async_client_chat(httpserver: HTTPServer):
|
||||||
httpserver.expect_ordered_request(
|
httpserver.expect_ordered_request(
|
||||||
'/api/chat',
|
'/api/chat',
|
||||||
@@ -1256,6 +1269,19 @@ async def test_async_client_copy(httpserver: HTTPServer):
|
|||||||
assert response['status'] == 'success'
|
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():
|
def test_headers():
|
||||||
client = Client()
|
client = Client()
|
||||||
assert client._client.headers['content-type'] == 'application/json'
|
assert client._client.headers['content-type'] == 'application/json'
|
||||||
|
|||||||
Reference in New Issue
Block a user