2
2
3
3
from __future__ import annotations
4
4
5
- from collections . abc import Iterable
5
+ from typing import Iterable
6
6
import textwrap
7
7
from typing import Any , Union , overload
8
8
import reprlib
@@ -278,7 +278,7 @@ def generate_content(
278
278
279
279
### Input type flexibility
280
280
281
- While the underlying API strictly expects a `list [protos.Content]` objects, this method
281
+ While the underlying API strictly expects a `List [protos.Content]` objects, this method
282
282
will convert the user input into the correct type. The hierarchy of types that can be
283
283
converted is below. Any of these objects can be passed as an equivalent `dict`.
284
284
@@ -504,7 +504,7 @@ def __init__(
504
504
enable_automatic_function_calling : bool = False ,
505
505
):
506
506
self .model : GenerativeModel = model
507
- self ._history : list [protos .Content ] = content_types .to_contents (history )
507
+ self ._history : List [protos .Content ] = content_types .to_contents (history )
508
508
self ._last_sent : protos .Content | None = None
509
509
self ._last_received : generation_types .BaseGenerateContentResponse | None = None
510
510
self .enable_automatic_function_calling = enable_automatic_function_calling
@@ -615,7 +615,7 @@ def _check_response(self, *, response, stream):
615
615
):
616
616
raise generation_types .StopCandidateException (response .candidates [0 ])
617
617
618
- def _get_function_calls (self , response ) -> list [protos .FunctionCall ]:
618
+ def _get_function_calls (self , response ) -> List [protos .FunctionCall ]:
619
619
candidates = response .candidates
620
620
if len (candidates ) != 1 :
621
621
raise ValueError (
@@ -635,14 +635,14 @@ def _handle_afc(
635
635
stream ,
636
636
tools_lib ,
637
637
request_options ,
638
- ) -> tuple [ list [protos .Content ], protos .Content , generation_types .BaseGenerateContentResponse ]:
638
+ ) -> Tuple [ List [protos .Content ], protos .Content , generation_types .BaseGenerateContentResponse ]:
639
639
640
640
while function_calls := self ._get_function_calls (response ):
641
641
if not all (callable (tools_lib [fc ]) for fc in function_calls ):
642
642
break
643
643
history .append (response .candidates [0 ].content )
644
644
645
- function_response_parts : list [protos .Part ] = []
645
+ function_response_parts : List [protos .Part ] = []
646
646
for fc in function_calls :
647
647
fr = tools_lib (fc )
648
648
assert fr is not None , (
@@ -742,14 +742,14 @@ async def _handle_afc_async(
742
742
stream ,
743
743
tools_lib ,
744
744
request_options ,
745
- ) -> tuple [ list [protos .Content ], protos .Content , generation_types .BaseGenerateContentResponse ]:
745
+ ) -> Tuple [ List [protos .Content ], protos .Content , generation_types .BaseGenerateContentResponse ]:
746
746
747
747
while function_calls := self ._get_function_calls (response ):
748
748
if not all (callable (tools_lib [fc ]) for fc in function_calls ):
749
749
break
750
750
history .append (response .candidates [0 ].content )
751
751
752
- function_response_parts : list [protos .Part ] = []
752
+ function_response_parts : List [protos .Part ] = []
753
753
for fc in function_calls :
754
754
fr = tools_lib (fc )
755
755
assert fr is not None , (
@@ -782,7 +782,7 @@ def __copy__(self):
782
782
history = list (self .history ),
783
783
)
784
784
785
- def rewind (self ) -> tuple [protos .Content , protos .Content ]:
785
+ def rewind (self ) -> Tuple [protos .Content , protos .Content ]:
786
786
"""Removes the last request/response pair from the chat history."""
787
787
if self ._last_received is None :
788
788
result = self ._history .pop (- 2 ), self ._history .pop ()
@@ -799,7 +799,7 @@ def last(self) -> generation_types.BaseGenerateContentResponse | None:
799
799
return self ._last_received
800
800
801
801
@property
802
- def history (self ) -> list [protos .Content ]:
802
+ def history (self ) -> List [protos .Content ]:
803
803
"""The chat history."""
804
804
last = self ._last_received
805
805
if last is None :
0 commit comments