Commit 9cc0149
committed
Add support for custom httpx client instances
Allow passing a pre-configured `httpx.Client` or `httpx.AsyncClient`
instance to reuse connections and custom configurations.
```python
import httpx
from ollama import Client
custom_httpx_client = httpx.Client(timeout=30.0)
client = Client(client=custom_httpx_client)
messages = [
{
'role': 'user',
'content': 'Why is the sky blue?',
},
]
for part in client.chat('gpt-oss:120b-cloud', messages=messages, stream=True):
print(part.message.content, end='', flush=True)
```
Note: this is an updated minimal version of
ollama#380 to support a custom
`httpx` client.
I took the approach of checking for the class instead of isinstance so
that nothing has to be a direct instance of an httpx.Client or
httpx.AsyncClient. It's up to the user to provide the right custom
client.1 parent dbccf19 commit 9cc0149
1 file changed
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
96 | 100 | | |
97 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
98 | 109 | | |
99 | 110 | | |
100 | 111 | | |
| |||
128 | 139 | | |
129 | 140 | | |
130 | 141 | | |
131 | | - | |
132 | | - | |
| 142 | + | |
| 143 | + | |
133 | 144 | | |
134 | 145 | | |
135 | 146 | | |
| |||
721 | 732 | | |
722 | 733 | | |
723 | 734 | | |
724 | | - | |
725 | | - | |
| 735 | + | |
| 736 | + | |
726 | 737 | | |
727 | 738 | | |
728 | 739 | | |
| |||
0 commit comments