Skip to content

Commit 2457042

Browse files
committed
Added Staging bucket and update requirements to include reasoning engine
1 parent 79f86ab commit 2457042

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

generative_ai/gemini_reasoning_engine.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@
1717
from vertexai.preview import reasoning_engines
1818

1919

20-
def create_reasoning_engine_basic(project_id: str) -> reasoning_engines.ReasoningEngine:
20+
def create_reasoning_engine_basic(
21+
project_id: str, staging_bucket: str
22+
) -> reasoning_engines.ReasoningEngine:
2123

2224
# [START generativeaionvertexai_create_reasoning_engine_basic]
2325
import vertexai
2426
from vertexai.preview import reasoning_engines
2527

2628
# TODO(developer): Update and un-comment below lines
2729
# project_id = "PROJECT_ID"
30+
# staging_bucket = "gs://YOUR_BUCKET_NAME"
2831

29-
vertexai.init(project=project_id, location="us-central1")
32+
vertexai.init(
33+
project=project_id, location="us-central1", staging_bucket=staging_bucket
34+
)
3035

3136
class SimpleAdditionApp:
3237
def query(self, a: int, b: int):
@@ -60,7 +65,7 @@ def query(self, a: int, b: int):
6065

6166

6267
def create_reasoning_engine_advanced(
63-
project_id: str, location: str
68+
project_id: str, location: str, staging_bucket: str
6469
) -> reasoning_engines.ReasoningEngine:
6570

6671
# [START generativeaionvertexai_create_reasoning_engine_advanced]
@@ -71,6 +76,9 @@ def create_reasoning_engine_advanced(
7176
# TODO(developer): Update and un-comment below lines
7277
# project_id = "PROJECT_ID"
7378
# location = "us-central1"
79+
# staging_bucket = "gs://YOUR_BUCKET_NAME"
80+
81+
vertexai.init(project=project_id, location=location, staging_bucket=staging_bucket)
7482

7583
class LangchainApp:
7684
def __init__(self, project: str, location: str):
@@ -108,8 +116,6 @@ def query(self, question: str):
108116
app.set_up()
109117
print(app.query("What is Vertex AI?"))
110118

111-
vertexai.init(project=project_id, location=location)
112-
113119
# Create a remote app with reasoning engine
114120
# This may take 1-2 minutes to finish because it builds a container and turn up HTTP servers.
115121
reasoning_engine = reasoning_engines.ReasoningEngine.create(

generative_ai/gemini_reasoning_engine_test.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
import sys
1617
from typing import Generator
1718

1819
import pytest
@@ -21,11 +22,15 @@
2122

2223
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
2324
REGION = "us-central1"
25+
STAGING_BUCKET = "gs://ucaip-samples-us-central1/reasoning_engine"
2426

2527

28+
@pytest.mark.skipif(sys.version_info >= (3, 12), reason="Python 3.12 is not supported")
2629
@pytest.fixture(scope="module")
2730
def reasoning_engine_id() -> Generator[str, None, None]:
28-
reasoning_engine = gemini_reasoning_engine.create_reasoning_engine_basic(PROJECT_ID)
31+
reasoning_engine = gemini_reasoning_engine.create_reasoning_engine_basic(
32+
PROJECT_ID, STAGING_BUCKET
33+
)
2934
yield reasoning_engine.resource_name
3035
print("Deleting Reasoning Engine...")
3136
gemini_reasoning_engine.delete_reasoning_engine(
@@ -39,7 +44,7 @@ def test_create_reasoning_engine_basic(reasoning_engine_id: str) -> None:
3944

4045
def test_create_reasoning_engine_advanced() -> None:
4146
reasoning_engine = gemini_reasoning_engine.create_reasoning_engine_advanced(
42-
PROJECT_ID, REGION
47+
PROJECT_ID, REGION, STAGING_BUCKET
4348
)
4449
assert reasoning_engine
4550
gemini_reasoning_engine.delete_reasoning_engine(

generative_ai/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ pandas==1.3.5; python_version == '3.7'
22
pandas==2.0.1; python_version > '3.7'
33
pillow==9.5.0; python_version < '3.8'
44
pillow==10.3.0; python_version >= '3.8'
5-
google-cloud-aiplatform[pipelines]==1.50.0
5+
google-cloud-aiplatform[pipelines,reasoningengine]==1.50.0
66
google-auth==2.17.3
77
anthropic[vertex]==0.25.6

0 commit comments

Comments
 (0)