2323
2424import pandas as pd
2525
26- from bigframes import clients , dataframe , dtypes , series , session
26+ from bigframes import dataframe , dtypes , series , session
2727from bigframes import pandas as bpd
2828from bigframes .bigquery ._operations import utils as bq_utils
2929from bigframes .core import convert
@@ -885,7 +885,11 @@ def classify(
885885 input : PROMPT_TYPE ,
886886 categories : tuple [str , ...] | list [str ],
887887 * ,
888+ examples : list [tuple [str , str ]] | None = None ,
888889 connection_id : str | None = None ,
890+ endpoint : str | None = None ,
891+ optimization_mode : Literal ["minimize_cost" , "maximize_quality" ] | None = None ,
892+ max_error_ratio : float | None = None ,
889893) -> series .Series :
890894 """
891895 Classifies a given input into one of the specified categories. It will always return one of the provided categories best fit the prompt input.
@@ -903,22 +907,30 @@ def classify(
903907 <BLANKLINE>
904908 [2 rows x 2 columns]
905909
906- .. note::
907-
908- This product or feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
909- Service Specific Terms(https://cloud.google.com/terms/service-terms#1). Pre-GA products and features are available "as is"
910- and might have limited support. For more information, see the launch stage descriptions
911- (https://cloud.google.com/products#product-launch-stages).
912-
913910 Args:
914911 input (str | Series | List[str|Series] | Tuple[str|Series, ...]):
915912 A mixture of Series and string literals that specifies the input to send to the model. The Series can be BigFrames Series
916913 or pandas Series.
917914 categories (tuple[str, ...] | list[str]):
918915 Categories to classify the input into.
916+ examples (list[tuple[str, str]], optional):
917+ An array that contains representative examples of input strings and the output category
918+ that you expect. You can provide examples to help the model understand your
919+ intended threshold for a condition with nuanced or subjective logic. We recommend providing at most 5 examples.
919920 connection_id (str, optional):
920921 Specifies the connection to use to communicate with the model. For example, `myproject.us.myconnection`.
921922 If not provided, the query uses your end-user credential.
923+ endpoint (str, optional):
924+ A STRING value that specifies the Vertex AI endpoint to use for the model. You can specify any
925+ generally available or preview Gemini model. If you specify the model name, BigQuery ML automatically
926+ identifies and uses the full endpoint of the model.
927+ optimization_mode (Literal["minimize_cost", "maximize_quality"], optional):
928+ A STRING value that specifies the optimization strategy to use. Supported values are ``minimize_cost``
929+ and ``maximize_quality``.
930+ max_error_ratio (float, optional):
931+ A value between ``0.0`` and ``1.0`` that contains the maximum acceptable ratio of row-level
932+ inference failures to rows processed on this function. The default value is 1.0.
933+ This argument isn't supported when ``optimization_mode`` is set to ``minimize_cost``.
922934
923935 Returns:
924936 bigframes.series.Series: A new series of strings.
@@ -927,10 +939,16 @@ def classify(
927939 prompt_context , series_list = _separate_context_and_series (input )
928940 assert len (series_list ) > 0
929941
942+ example_tuples = tuple (examples ) if examples is not None else None
943+
930944 operator = ai_ops .AIClassify (
931945 prompt_context = tuple (prompt_context ),
932946 categories = tuple (categories ),
947+ examples = example_tuples ,
933948 connection_id = connection_id ,
949+ endpoint = endpoint ,
950+ optimization_mode = optimization_mode ,
951+ max_error_ratio = max_error_ratio ,
934952 )
935953
936954 return series_list [0 ]._apply_nary_op (operator , series_list [1 :])
@@ -1249,14 +1267,6 @@ def _convert_series(
12491267 return result
12501268
12511269
1252- def _resolve_connection_id (series : series .Series , connection_id : str | None ):
1253- return clients .get_canonical_bq_connection_id (
1254- connection_id or series ._session .bq_connection ,
1255- series ._session ._project ,
1256- series ._session ._location ,
1257- )
1258-
1259-
12601270def _to_dataframe (
12611271 data : Union [dataframe .DataFrame , series .Series , pd .DataFrame , pd .Series ],
12621272 series_rename : str ,
0 commit comments