Skip to content

Commit 3fb72f0

Browse files
committed
fix: update type hints for async message streaming in GeminiLLM
1 parent b87b512 commit 3fb72f0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

plugins/gemini/vision_agents/plugins/gemini/gemini_llm.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid
2-
from typing import Optional, List, TYPE_CHECKING, Any, Dict
2+
from typing import Optional, List, TYPE_CHECKING, Any, Dict, AsyncIterator
33

44
from google.genai.client import AsyncClient, Client
55
from google.genai import types
@@ -99,7 +99,7 @@ async def send_message(self, *args, **kwargs):
9999
kwargs["config"] = cfg
100100

101101
# Generate content using the client
102-
iterator = await self.chat.send_message_stream(*args, **kwargs)
102+
iterator: AsyncIterator[GenerateContentResponse] = self.chat.send_message_stream(*args, **kwargs) # type: ignore[assignment]
103103
text_parts : List[str] = []
104104
final_chunk = None
105105
pending_calls: List[NormalizedToolCallItem] = []
@@ -149,23 +149,26 @@ async def send_message(self, *args, **kwargs):
149149
parts.append(types.Part.from_function_response(name=tc["name"], response=sanitized_res))
150150

151151
# Send function responses with tools config
152-
follow_up_iter = self.chat.send_message_stream(parts, config=cfg_with_tools) # type: ignore[arg-type]
152+
follow_up_iter: AsyncIterator[GenerateContentResponse] = self.chat.send_message_stream(parts, config=cfg_with_tools) # type: ignore[arg-type,assignment]
153153

154154
follow_up_text_parts: List[str] = []
155155
follow_up_last = None
156156
next_calls = []
157+
follow_up_idx = 0
157158

158-
for idx, chk in enumerate(follow_up_iter):
159+
async for chk in follow_up_iter:
159160
follow_up_last = chk
160161
# TODO: unclear if this is correct (item_id and idx)
161-
self._standardize_and_emit_event(chk, follow_up_text_parts, item_id, idx)
162+
self._standardize_and_emit_event(chk, follow_up_text_parts, item_id, follow_up_idx)
162163

163164
# Check for new function calls
164165
try:
165166
chunk_calls = self._extract_tool_calls_from_stream_chunk(chk)
166167
next_calls.extend(chunk_calls)
167168
except Exception:
168169
pass
170+
171+
follow_up_idx += 1
169172

170173
current_calls = next_calls
171174
rounds += 1

0 commit comments

Comments
 (0)