|
1 | 1 | import uuid |
2 | | -from typing import Optional, List, TYPE_CHECKING, Any, Dict |
| 2 | +from typing import Optional, List, TYPE_CHECKING, Any, Dict, AsyncIterator |
3 | 3 |
|
4 | 4 | from google.genai.client import AsyncClient, Client |
5 | 5 | from google.genai import types |
@@ -99,7 +99,7 @@ async def send_message(self, *args, **kwargs): |
99 | 99 | kwargs["config"] = cfg |
100 | 100 |
|
101 | 101 | # 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] |
103 | 103 | text_parts : List[str] = [] |
104 | 104 | final_chunk = None |
105 | 105 | pending_calls: List[NormalizedToolCallItem] = [] |
@@ -149,23 +149,26 @@ async def send_message(self, *args, **kwargs): |
149 | 149 | parts.append(types.Part.from_function_response(name=tc["name"], response=sanitized_res)) |
150 | 150 |
|
151 | 151 | # 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] |
153 | 153 |
|
154 | 154 | follow_up_text_parts: List[str] = [] |
155 | 155 | follow_up_last = None |
156 | 156 | next_calls = [] |
| 157 | + follow_up_idx = 0 |
157 | 158 |
|
158 | | - for idx, chk in enumerate(follow_up_iter): |
| 159 | + async for chk in follow_up_iter: |
159 | 160 | follow_up_last = chk |
160 | 161 | # 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) |
162 | 163 |
|
163 | 164 | # Check for new function calls |
164 | 165 | try: |
165 | 166 | chunk_calls = self._extract_tool_calls_from_stream_chunk(chk) |
166 | 167 | next_calls.extend(chunk_calls) |
167 | 168 | except Exception: |
168 | 169 | pass |
| 170 | + |
| 171 | + follow_up_idx += 1 |
169 | 172 |
|
170 | 173 | current_calls = next_calls |
171 | 174 | rounds += 1 |
|
0 commit comments