Build, test, and deploy a custom app on Reasoning Engine

This sample demonstrates how to build, test, and deploy a custom app on Reasoning Engine. It includes a local test of the app and the steps to deploy the app on the Reasoning Engine.

Code sample

Python

Before trying this sample, follow the Python setup instructions in the Vertex AI quickstart using client libraries. For more information, see the Vertex AI Python API reference documentation.

To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

importvertexai
fromvertexai.previewimport reasoning_engines
# TODO(developer): Update and un-comment below lines
# PROJECT_ID = "your-project-id"
# staging_bucket = "gs://YOUR_BUCKET_NAME"
vertexai .init(
 project=PROJECT_ID, location="us-central1", staging_bucket=staging_bucket
)
classSimpleAdditionApp:
 defquery(self, a: int, b: int) -> str:
"""Query the application.
 Args:
 a: The first input number
 b: The second input number
 Returns:
 int: The additional result.
 """
 return f"{int(a)} + {int(b)} is {int(a+b)}"
# Locally test
app = SimpleAdditionApp()
app.query(a=1, b=2)
# Create a remote app with Reasoning Engine.
# This may take 1-2 minutes to finish.
reasoning_engine = reasoning_engines .ReasoningEngine .create(
 SimpleAdditionApp(),
 display_name="Demo Addition App",
 description="A simple demo addition app",
 requirements=["cloudpickle==3"],
 extra_packages=[],
)
# Example response:
# Using bucket YOUR_BUCKET_NAME
# Writing to gs://YOUR_BUCKET_NAME/reasoning_engine/reasoning_engine.pkl
# ...
# ReasoningEngine created. Resource name: projects/123456789/locations/us-central1/reasoningEngines/123456
# To use this ReasoningEngine in another session:
# reasoning_engine = vertexai.preview.reasoning_engines.ReasoningEngine('projects/123456789/locations/...

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.