@@ -68,14 +68,12 @@ def __init__(
68
68
ollama_client_args: Additional arguments for the Ollama client.
69
69
**model_config: Configuration options for the Ollama model.
70
70
"""
71
+ self .host = host
72
+ self .client_args = ollama_client_args or {}
71
73
self .config = OllamaModel .OllamaConfig (** model_config )
72
74
73
75
logger .debug ("config=<%s> | initializing" , self .config )
74
76
75
- ollama_client_args = ollama_client_args if ollama_client_args is not None else {}
76
-
77
- self .client = ollama .AsyncClient (host , ** ollama_client_args )
78
-
79
77
@override
80
78
def update_config (self , ** model_config : Unpack [OllamaConfig ]) -> None : # type: ignore
81
79
"""Update the Ollama Model configuration with the provided arguments.
@@ -306,7 +304,8 @@ async def stream(
306
304
logger .debug ("invoking model" )
307
305
tool_requested = False
308
306
309
- response = await self .client .chat (** request )
307
+ client = ollama .AsyncClient (self .host , ** self .client_args )
308
+ response = await client .chat (** request )
310
309
311
310
logger .debug ("got response from model" )
312
311
yield self .format_chunk ({"chunk_type" : "message_start" })
@@ -346,7 +345,9 @@ async def structured_output(
346
345
formatted_request = self .format_request (messages = prompt )
347
346
formatted_request ["format" ] = output_model .model_json_schema ()
348
347
formatted_request ["stream" ] = False
349
- response = await self .client .chat (** formatted_request )
348
+
349
+ client = ollama .AsyncClient (self .host , ** self .client_args )
350
+ response = await client .chat (** formatted_request )
350
351
351
352
try :
352
353
content = response .message .content .strip ()
0 commit comments