mirror of
https://github.com/ollama/ollama-python.git
synced 2026-05-01 11:48:17 +08:00
Merge 5e280163bd into dbccf192ac
This commit is contained in:
commit
85332c4c3f
@ -57,3 +57,4 @@ show = _client.show
|
||||
ps = _client.ps
|
||||
web_search = _client.web_search
|
||||
web_fetch = _client.web_fetch
|
||||
ping = _client.ping
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user