@@ -824,7 +824,7 @@ async def async_generator():
824
824
return async_generator ()
825
825
826
826
def count_tokens (
827
- self , contents : ContentsType
827
+ self , contents : ContentsType , * , tools : Optional [ List [ "Tool" ]] = None
828
828
) -> gapic_prediction_service_types .CountTokensResponse :
829
829
"""Counts tokens.
830
830
@@ -836,22 +836,32 @@ def count_tokens(
836
836
* str, Image, Part,
837
837
* List[Union[str, Image, Part]],
838
838
* List[Content]
839
+ tools: A list of tools (functions) that the model can try calling.
839
840
840
841
Returns:
841
842
A CountTokensResponse object that has the following attributes:
842
843
total_tokens: The total number of tokens counted across all instances from the request.
843
844
total_billable_characters: The total number of billable characters counted across all instances from the request.
844
845
"""
846
+ request = self ._prepare_request (
847
+ contents = contents ,
848
+ tools = tools ,
849
+ )
845
850
return self ._prediction_client .count_tokens (
846
851
request = gapic_prediction_service_types .CountTokensRequest (
847
852
endpoint = self ._prediction_resource_name ,
848
853
model = self ._prediction_resource_name ,
849
- contents = self ._prepare_request (contents = contents ).contents ,
854
+ contents = request .contents ,
855
+ system_instruction = request .system_instruction ,
856
+ tools = request .tools ,
850
857
)
851
858
)
852
859
853
860
async def count_tokens_async (
854
- self , contents : ContentsType
861
+ self ,
862
+ contents : ContentsType ,
863
+ * ,
864
+ tools : Optional [List ["Tool" ]] = None ,
855
865
) -> gapic_prediction_service_types .CountTokensResponse :
856
866
"""Counts tokens asynchronously.
857
867
@@ -863,17 +873,24 @@ async def count_tokens_async(
863
873
* str, Image, Part,
864
874
* List[Union[str, Image, Part]],
865
875
* List[Content]
876
+ tools: A list of tools (functions) that the model can try calling.
866
877
867
878
Returns:
868
879
And awaitable for a CountTokensResponse object that has the following attributes:
869
880
total_tokens: The total number of tokens counted across all instances from the request.
870
881
total_billable_characters: The total number of billable characters counted across all instances from the request.
871
882
"""
883
+ request = self ._prepare_request (
884
+ contents = contents ,
885
+ tools = tools ,
886
+ )
872
887
return await self ._prediction_async_client .count_tokens (
873
888
request = gapic_prediction_service_types .CountTokensRequest (
874
889
endpoint = self ._prediction_resource_name ,
875
890
model = self ._prediction_resource_name ,
876
- contents = self ._prepare_request (contents = contents ).contents ,
891
+ contents = request .contents ,
892
+ system_instruction = request .system_instruction ,
893
+ tools = request .tools ,
877
894
)
878
895
)
879
896
0 commit comments