Skip to content

Commit

Permalink
Merge pull request #5 from jmorganca/mxyng
Browse files Browse the repository at this point in the history
Mxyng
  • Loading branch information
mxyng authored Jan 11, 2024
2 parents 0f9211d + 1f68bae commit efc7ea3
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 46 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ async def chat():

asyncio.run(chat())
```

## Handling Errors

Errors are raised if requests return an error status or if an error is detected while streaming.

```python
model = 'does-not-yet-exist'

try:
ollama.chat(model)
except ollama.ResponseError as e:
print('Error:', e.content)
if e.status_code == 404:
ollama.pull(model)
```
17 changes: 16 additions & 1 deletion ollama/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
from ollama._client import Client, AsyncClient
from ollama._types import Message, Options
from ollama._types import (
GenerateResponse,
ChatResponse,
ProgressResponse,
Message,
Options,
RequestError,
ResponseError,
)

__all__ = [
'Client',
'AsyncClient',
'GenerateResponse',
'ChatResponse',
'ProgressResponse',
'Message',
'Options',
'RequestError',
'ResponseError',
'generate',
'chat',
'embeddings',
'pull',
'push',
'create',
Expand All @@ -21,6 +35,7 @@

generate = _client.generate
chat = _client.chat
embeddings = _client.embeddings
pull = _client.pull
push = _client.push
create = _client.create
Expand Down
Loading

0 comments on commit efc7ea3

Please sign in to comment.