Skip to content

Commit

Permalink
chore: Combine reasoning engine system tests into one test method.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 632336753
  • Loading branch information
Yeesian Ng authored and Copybara-Service committed May 10, 2024
1 parent 32b030a commit 9145089
Showing 1 changed file with 13 additions and 54 deletions.
67 changes: 13 additions & 54 deletions tests/system/vertexai/test_reasoning_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestReasoningEngines(e2e_base.TestEndToEnd):

_temp_prefix = "test-reasoning-engine"

def test_langchain_template(self, shared_state):
def test_reasoning_engine_all(self, shared_state):
super().setup_method()
credentials, _ = auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
Expand All @@ -53,9 +53,13 @@ def test_langchain_template(self, shared_state):
staging_bucket=f"gs://{shared_state['staging_bucket_name']}",
credentials=credentials,
)
# Test prebuilt langchain_template
created_app = reasoning_engines.ReasoningEngine.create(
reasoning_engines.LangchainAgent(model="gemini-1.0-pro"),
requirements=["google-cloud-aiplatform[reasoningengine,langchain]"],
reasoning_engine_name="test-reasoning-engine-name",
display_name="test-display-name",
description="test-description",
)
shared_state.setdefault("resources", [])
shared_state["resources"].append(created_app) # Deletion at teardown.
Expand All @@ -64,70 +68,25 @@ def test_langchain_template(self, shared_state):
assert response.get("input") == "hello"
assert isinstance(created_app.resource_name, str)
got_app = reasoning_engines.ReasoningEngine(created_app.resource_name)
# Test resource attributes
assert got_app.resource_name == created_app.resource_name
assert got_app.gca_resource.name == "test-reasoning-engine-name"
assert got_app.gca_resource.display_name == "test-display-name"
assert got_app.gca_resource.description == "test-description"
# Test operation schemas
assert got_app.operation_schemas() == created_app.operation_schemas()
# Test query response
response = got_app.query(input="hello")
assert response.get("input") == "hello"
except exceptions.FailedPrecondition as e:
print(e)

def test_create_reasoning_engine_gcs_dir_name(self, shared_state):
# https://github.com/googleapis/python-aiplatform/issues/3650
super().setup_method()
credentials, _ = auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
vertexai.init(
project=e2e_base._PROJECT,
location=e2e_base._LOCATION,
staging_bucket=f"gs://{shared_state['staging_bucket_name']}",
credentials=credentials,
)
# Test GCS Bucket subdirectory creation
# Original: https://github.com/googleapis/python-aiplatform/issues/3650
created_app = reasoning_engines.ReasoningEngine.create(
reasoning_engine=CapitalizeEngine(),
gcs_dir_name="test-gcs-dir-name",
)
shared_state.setdefault("resources", [])
shared_state["resources"].append(created_app) # Deletion at teardown.
assert created_app.query(input="hello") == "HELLO"

def test_create_reasoning_engine_resource_attributes(self, shared_state):
super().setup_method()
credentials, _ = auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
vertexai.init(
project=e2e_base._PROJECT,
location=e2e_base._LOCATION,
staging_bucket=f"gs://{shared_state['staging_bucket_name']}",
credentials=credentials,
)
created_app = reasoning_engines.ReasoningEngine.create(
reasoning_engine=CapitalizeEngine(),
reasoning_engine_name="test-reasoning-engine-name",
display_name="test-display-name",
description="test-description",
)
shared_state.setdefault("resources", [])
shared_state["resources"].append(created_app) # Deletion at teardown.
assert created_app.gca_resource.name == "test-reasoning-engine-name"
assert created_app.gca_resource.display_name == "test-display-name"
assert created_app.gca_resource.description == "test-description"

def test_create_reasoning_engine_operation_schemas(self, shared_state):
super().setup_method()
credentials, _ = auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)
vertexai.init(
project=e2e_base._PROJECT,
location=e2e_base._LOCATION,
staging_bucket=f"gs://{shared_state['staging_bucket_name']}",
credentials=credentials,
)
created_app = reasoning_engines.ReasoningEngine.create(
reasoning_engine=CapitalizeEngine(),
)
shared_state.setdefault("resources", [])
shared_state["resources"].append(created_app) # Deletion at teardown.
assert created_app.operation_schemas() == []

0 comments on commit 9145089

Please sign in to comment.