bigframes.bigquery.ai.generate_text#
- bigframes.bigquery.ai.generate_text(model: BaseEstimator | str | Series, data: DataFrame | Series | DataFrame | Series, *, temperature: float | None = None, max_output_tokens: int | None = None, top_k: int | None = None, top_p: float | None = None, stop_sequences: List[str] | None = None, ground_with_google_search: bool | None = None, request_type: str | None = None) DataFrame[source]#
Generates text using a BigQuery ML model.
See the BigQuery ML GENERATE_TEXT function syntax for additional reference.
Examples:
>>> import bigframes.pandas as bpd >>> import bigframes.bigquery as bbq >>> df = bpd.DataFrame({"prompt": ["write a poem about apples"]}) >>> bbq.ai.generate_text( ... "project.dataset.model_name", ... df ... )
- Parameters:
model (bigframes.ml.base.BaseEstimator or str) – The model to use for text generation.
data (bigframes.pandas.DataFrame or bigframes.pandas.Series) – The data to generate embeddings for. If a Series is provided, it is treated as the ‘content’ column. If a DataFrame is provided, it must contain a ‘content’ column, or you must rename the column you wish to embed to ‘content’.
temperature (float, optional) – A FLOAT64 value that is used for sampling promiscuity. The value must be in the range
[0.0, 1.0]. A lower temperature works well for prompts that expect a more deterministic and less open-ended or creative response, while a higher temperature can lead to more diverse or creative results. A temperature of0is deterministic, meaning that the highest probability response is always selected.max_output_tokens (int, optional) – An INT64 value that sets the maximum number of tokens in the generated text.
top_k (int, optional) – An INT64 value that changes how the model selects tokens for output. A
top_kof1means the next selected token is the most probable among all tokens in the model’s vocabulary. Atop_kof3means that the next token is selected from among the three most probable tokens by using temperature. The default value is40.top_p (float, optional) – A FLOAT64 value that changes how the model selects tokens for output. Tokens are selected from most probable to least probable until the sum of their probabilities equals the
top_pvalue. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and thetop_pvalue is0.5, then the model will select either A or B as the next token by using temperature. The default value is0.95.stop_sequences (List[str], optional) – An ARRAY<STRING> value that contains the stop sequences for the model.
ground_with_google_search (bool, optional) – A BOOL value that determines whether to ground the model with Google Search.
request_type (str, optional) – A STRING value that contains the request type for the model.
- Returns:
The generated text.
- Return type: