@@ -63,8 +63,7 @@ def __init__(
6363
6464 logger .debug ("config=<%s> | initializing" , self .config )
6565
66- client_args = client_args or {}
67- self .client = genai .Client (** client_args )
66+ self .client_args = client_args or {}
6867
6968 @override
7069 def update_config (self , ** model_config : Unpack [GeminiConfig ]) -> None : # type: ignore[override]
@@ -366,8 +365,9 @@ async def stream(
366365 """
367366 request = self ._format_request (messages , tool_specs , system_prompt , self .config .get ("params" ))
368367
368+ client = genai .Client (** self .client_args ).aio
369369 try :
370- response = await self . client . aio .models .generate_content_stream (** request )
370+ response = await client .models .generate_content_stream (** request )
371371
372372 yield self ._format_chunk ({"chunk_type" : "message_start" })
373373 yield self ._format_chunk ({"chunk_type" : "content_start" , "data_type" : "text" })
@@ -442,5 +442,6 @@ async def structured_output(
442442 "response_schema" : output_model .model_json_schema (),
443443 }
444444 request = self ._format_request (prompt , None , system_prompt , params )
445- response = await self .client .aio .models .generate_content (** request )
445+ client = genai .Client (** self .client_args ).aio
446+ response = await client .models .generate_content (** request )
446447 yield {"output" : output_model .model_validate (response .parsed )}
0 commit comments