|
20 | 20 | import sys
|
21 | 21 | import tarfile
|
22 | 22 | import typing
|
23 |
| -from typing import Optional, Protocol, Sequence |
| 23 | +from typing import Optional, Protocol, Sequence, Union |
24 | 24 |
|
25 | 25 | from google.cloud.aiplatform import base
|
26 | 26 | from google.cloud.aiplatform import initializer
|
@@ -84,7 +84,7 @@ def create(
|
84 | 84 | cls,
|
85 | 85 | reasoning_engine: Queryable,
|
86 | 86 | *,
|
87 |
| - requirements: Optional[Sequence[str]] = None, |
| 87 | + requirements: Optional[Union[str, Sequence[str]]] = None, |
88 | 88 | reasoning_engine_name: Optional[str] = None,
|
89 | 89 | display_name: Optional[str] = None,
|
90 | 90 | description: Optional[str] = None,
|
@@ -131,8 +131,10 @@ def create(
|
131 | 131 | Args:
|
132 | 132 | reasoning_engine (ReasoningEngineInterface):
|
133 | 133 | Required. The Reasoning Engine to be created.
|
134 |
| - requirements (Sequence[str]): |
135 |
| - Optional. The set of PyPI dependencies needed. |
| 134 | + requirements (Union[str, Sequence[str]]): |
| 135 | + Optional. The set of PyPI dependencies needed. It can either be |
| 136 | + the path to a single file (requirements.txt), or an ordered list |
| 137 | + of strings corresponding to each line of the requirements file. |
136 | 138 | reasoning_engine_name (str):
|
137 | 139 | Optional. A fully-qualified resource name or ID such as
|
138 | 140 | "projects/123/locations/us-central1/reasoningEngines/456" or
|
@@ -202,6 +204,16 @@ def create(
|
202 | 204 | "Invalid query signature. This might be due to a missing "
|
203 | 205 | "`self` argument in the reasoning_engine.query method."
|
204 | 206 | ) from err
|
| 207 | + if isinstance(requirements, str): |
| 208 | + try: |
| 209 | + _LOGGER.info(f"Reading requirements from {requirements=}") |
| 210 | + with open(requirements) as f: |
| 211 | + requirements = f.read().splitlines() |
| 212 | + _LOGGER.info(f"Read the following lines: {requirements}") |
| 213 | + except IOError as err: |
| 214 | + raise IOError( |
| 215 | + f"Failed to read requirements from {requirements=}" |
| 216 | + ) from err |
205 | 217 | requirements = requirements or []
|
206 | 218 | extra_packages = extra_packages or []
|
207 | 219 | for extra_package in extra_packages:
|
|
0 commit comments