|
15 | 15 | from __future__ import annotations |
16 | 16 |
|
17 | 17 | import abc |
18 | | -from typing import TYPE_CHECKING, Generic, Iterable, TypeVar |
| 18 | +from typing import ( |
| 19 | + TYPE_CHECKING, |
| 20 | + Any, |
| 21 | + Generic, |
| 22 | + Iterable, |
| 23 | + List, |
| 24 | + Literal, |
| 25 | + Mapping, |
| 26 | + Tuple, |
| 27 | + TypeVar, |
| 28 | + Union, |
| 29 | +) |
19 | 30 |
|
20 | 31 | if TYPE_CHECKING: |
| 32 | + import pandas as pd |
| 33 | + |
21 | 34 | import bigframes.dataframe |
| 35 | + import bigframes.series |
22 | 36 | import bigframes.session |
23 | 37 |
|
| 38 | + PROMPT_TYPE = Union[ |
| 39 | + str, |
| 40 | + bigframes.series.Series, |
| 41 | + pd.Series, |
| 42 | + List[Union[str, bigframes.series.Series, pd.Series]], |
| 43 | + Tuple[Union[str, bigframes.series.Series, pd.Series], ...], |
| 44 | + ] |
| 45 | +else: |
| 46 | + PROMPT_TYPE = Any |
| 47 | + |
24 | 48 | T = TypeVar("T") |
25 | 49 | S = TypeVar("S") |
26 | 50 |
|
@@ -84,6 +108,112 @@ def forecast( |
84 | 108 | ) |
85 | 109 | return self._to_dataframe(result) |
86 | 110 |
|
| 111 | + def generate( |
| 112 | + self, |
| 113 | + prompt: PROMPT_TYPE, |
| 114 | + *, |
| 115 | + connection_id: str | None = None, |
| 116 | + endpoint: str | None = None, |
| 117 | + request_type: Literal["dedicated", "shared", "unspecified"] | None = None, |
| 118 | + model_params: Mapping[Any, Any] | None = None, |
| 119 | + output_schema: Mapping[str, str] | None = None, |
| 120 | + ) -> S: |
| 121 | + """ |
| 122 | + Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data. |
| 123 | +
|
| 124 | + This is an accessor for :func:`bigframes.bigquery.ai.generate`. See that |
| 125 | + function's documentation for detailed parameter descriptions and examples. |
| 126 | + """ |
| 127 | + import bigframes.bigquery.ai |
| 128 | + |
| 129 | + result = bigframes.bigquery.ai.generate( |
| 130 | + prompt, |
| 131 | + connection_id=connection_id, |
| 132 | + endpoint=endpoint, |
| 133 | + request_type=request_type, |
| 134 | + model_params=model_params, |
| 135 | + output_schema=output_schema, |
| 136 | + ) |
| 137 | + return self._to_series(result) |
| 138 | + |
| 139 | + def generate_bool( |
| 140 | + self, |
| 141 | + prompt: PROMPT_TYPE, |
| 142 | + *, |
| 143 | + connection_id: str | None = None, |
| 144 | + endpoint: str | None = None, |
| 145 | + request_type: Literal["dedicated", "shared", "unspecified"] | None = None, |
| 146 | + model_params: Mapping[Any, Any] | None = None, |
| 147 | + ) -> S: |
| 148 | + """ |
| 149 | + Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data. |
| 150 | +
|
| 151 | + This is an accessor for :func:`bigframes.bigquery.ai.generate_bool`. See that |
| 152 | + function's documentation for detailed parameter descriptions and examples. |
| 153 | + """ |
| 154 | + import bigframes.bigquery.ai |
| 155 | + |
| 156 | + result = bigframes.bigquery.ai.generate_bool( |
| 157 | + prompt, |
| 158 | + connection_id=connection_id, |
| 159 | + endpoint=endpoint, |
| 160 | + request_type=request_type, |
| 161 | + model_params=model_params, |
| 162 | + ) |
| 163 | + return self._to_series(result) |
| 164 | + |
| 165 | + def generate_int( |
| 166 | + self, |
| 167 | + prompt: PROMPT_TYPE, |
| 168 | + *, |
| 169 | + connection_id: str | None = None, |
| 170 | + endpoint: str | None = None, |
| 171 | + request_type: Literal["dedicated", "shared", "unspecified"] | None = None, |
| 172 | + model_params: Mapping[Any, Any] | None = None, |
| 173 | + ) -> S: |
| 174 | + """ |
| 175 | + Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data. |
| 176 | +
|
| 177 | + This is an accessor for :func:`bigframes.bigquery.ai.generate_int`. See that |
| 178 | + function's documentation for detailed parameter descriptions and examples. |
| 179 | + """ |
| 180 | + import bigframes.bigquery.ai |
| 181 | + |
| 182 | + result = bigframes.bigquery.ai.generate_int( |
| 183 | + prompt, |
| 184 | + connection_id=connection_id, |
| 185 | + endpoint=endpoint, |
| 186 | + request_type=request_type, |
| 187 | + model_params=model_params, |
| 188 | + ) |
| 189 | + return self._to_series(result) |
| 190 | + |
| 191 | + def generate_double( |
| 192 | + self, |
| 193 | + prompt: PROMPT_TYPE, |
| 194 | + *, |
| 195 | + connection_id: str | None = None, |
| 196 | + endpoint: str | None = None, |
| 197 | + request_type: Literal["dedicated", "shared", "unspecified"] | None = None, |
| 198 | + model_params: Mapping[Any, Any] | None = None, |
| 199 | + ) -> S: |
| 200 | + """ |
| 201 | + Returns the AI analysis based on the prompt, which can be any combination of text and unstructured data. |
| 202 | +
|
| 203 | + This is an accessor for :func:`bigframes.bigquery.ai.generate_double`. See that |
| 204 | + function's documentation for detailed parameter descriptions and examples. |
| 205 | + """ |
| 206 | + import bigframes.bigquery.ai |
| 207 | + |
| 208 | + result = bigframes.bigquery.ai.generate_double( |
| 209 | + prompt, |
| 210 | + connection_id=connection_id, |
| 211 | + endpoint=endpoint, |
| 212 | + request_type=request_type, |
| 213 | + model_params=model_params, |
| 214 | + ) |
| 215 | + return self._to_series(result) |
| 216 | + |
87 | 217 |
|
88 | 218 | class BigQueryDataFrameAccessor(AbstractBigQueryDataFrameAccessor[T, S]): |
89 | 219 | """ |
|
0 commit comments