mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 14:42:04 +00:00
rename notebook name as model_garden_integration_with_agent, which provides examples for adk/agent engine etc.
PiperOrigin-RevId: 763954229
This commit is contained in:
committed by
Copybara-Service
parent
0fcf2fb285
commit
21bb972b85
+29
-29
@@ -34,12 +34,12 @@
|
||||
"\n",
|
||||
"\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\n",
|
||||
" \u003ctd style=\"text-align: center\"\u003e\n",
|
||||
" \u003ca href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fcommunity%2Fmodel_garden%2Fmodel_garden_integration_with_adk.ipynb\"\u003e\n",
|
||||
" \u003ca href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fcommunity%2Fmodel_garden%2Fmodel_garden_integration_with_agent.ipynb\"\u003e\n",
|
||||
" \u003cimg alt=\"Google Cloud Colab Enterprise logo\" src=\"https://lh3.googleusercontent.com/JmcxdQi-qOpctIvWKgPtrzZdJJK-J3sWE1RsfjZNwshCFgE_9fULcNpuXYTilIR2hjwN\" width=\"32px\"\u003e\u003cbr\u003e Run in Colab Enterprise\n",
|
||||
" \u003c/a\u003e\n",
|
||||
" \u003c/td\u003e\n",
|
||||
" \u003ctd style=\"text-align: center\"\u003e\n",
|
||||
" \u003ca href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/model_garden/model_garden_integration_with_adk.ipynb\"\u003e\n",
|
||||
" \u003ca href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/model_garden/model_garden_integration_with_agent.ipynb\"\u003e\n",
|
||||
" \u003cimg alt=\"GitHub logo\" src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" width=\"32px\"\u003e\u003cbr\u003e View on GitHub\n",
|
||||
" \u003c/a\u003e\n",
|
||||
" \u003c/td\u003e\n",
|
||||
@@ -462,9 +462,9 @@
|
||||
"\n",
|
||||
"location = endpoint_resource_name.split('/')[3]\n",
|
||||
"if endpoint.gca_resource.dedicated_endpoint_enabled:\n",
|
||||
" base_url = f\"https://{endpoint.gca_resource.dedicated_endpoint_dns}/v1beta1/{endpoint.resource_name}\"\n",
|
||||
" base_url = f\"https://{endpoint.gca_resource.dedicated_endpoint_dns}/v1beta1/{endpoint.resource_name}\"\n",
|
||||
"else:\n",
|
||||
" base_url = f\"https://{location}-aiplatform.googleapis.com/v1beta1/{endpoint.resource_name}\"\n",
|
||||
" base_url = f\"https://{location}-aiplatform.googleapis.com/v1beta1/{endpoint.resource_name}\"\n",
|
||||
"\n",
|
||||
"# @markdown Predict locally with some requests.\n",
|
||||
"\n",
|
||||
@@ -745,9 +745,9 @@
|
||||
"endpoint = aiplatform.Endpoint(endpoint_resource_name)\n",
|
||||
"location = endpoint_resource_name.split('/')[3]\n",
|
||||
"if endpoint.gca_resource.dedicated_endpoint_enabled:\n",
|
||||
" base_url = f\"https://{endpoint.gca_resource.dedicated_endpoint_dns}/v1beta1/{endpoint.resource_name}\"\n",
|
||||
" base_url = f\"https://{endpoint.gca_resource.dedicated_endpoint_dns}/v1beta1/{endpoint.resource_name}\"\n",
|
||||
"else:\n",
|
||||
" base_url = f\"https://{location}-aiplatform.googleapis.com/v1beta1/{endpoint.resource_name}\"\n",
|
||||
" base_url = f\"https://{location}-aiplatform.googleapis.com/v1beta1/{endpoint.resource_name}\"\n",
|
||||
"\n",
|
||||
"def model_builder(\n",
|
||||
" *,\n",
|
||||
@@ -808,7 +808,7 @@
|
||||
" return store[session_id]\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"agent = agent_engines.LangchainAgent( #reasoning_engines\n",
|
||||
"agent = agent_engines.LangchainAgent(\n",
|
||||
" prompt=prompt,\n",
|
||||
" model=\"\", # Required.\n",
|
||||
" chat_history=get_session_history,\n",
|
||||
@@ -834,33 +834,33 @@
|
||||
"# @markdown You can check the agent result before deploying to Vertex AI.\n",
|
||||
"\n",
|
||||
"def test_agent(running_agent, query, session_id):\n",
|
||||
" response = running_agent.query(\n",
|
||||
" input={\n",
|
||||
" \"system_prompt\": [(\"system\", system_prompt_with_tools)],\n",
|
||||
" \"input\": query,\n",
|
||||
" \"ai_prompt\": [],\n",
|
||||
" },\n",
|
||||
" config={\"configurable\": {\"session_id\": session_id}},\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" tool_results = call_tools(response[\"output\"])\n",
|
||||
"\n",
|
||||
" if tool_results:\n",
|
||||
" temporal_result = response[\"output\"] + json.dumps(tool_results)\n",
|
||||
" response = running_agent.query(\n",
|
||||
" input={\n",
|
||||
" \"system_prompt\": [(\"system\", system_prompt_without_tools)],\n",
|
||||
" \"ai_prompt\": [(\"ai\", temporal_result)],\n",
|
||||
" \"system_prompt\": [(\"system\", system_prompt_with_tools)],\n",
|
||||
" \"input\": query,\n",
|
||||
" \"ai_prompt\": [],\n",
|
||||
" },\n",
|
||||
" config={\"configurable\": {\"session_id\": session_id}},\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" print(response[\"output\"])\n",
|
||||
" tool_results = call_tools(response[\"output\"])\n",
|
||||
"\n",
|
||||
" if tool_results:\n",
|
||||
" temporal_result = response[\"output\"] + json.dumps(tool_results)\n",
|
||||
" response = running_agent.query(\n",
|
||||
" input={\n",
|
||||
" \"system_prompt\": [(\"system\", system_prompt_without_tools)],\n",
|
||||
" \"ai_prompt\": [(\"ai\", temporal_result)],\n",
|
||||
" \"input\": query,\n",
|
||||
" },\n",
|
||||
" config={\"configurable\": {\"session_id\": session_id}},\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" print(response[\"output\"])\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"query = \"What is the weather in SF?\" # @param {type:\"string\"}\n",
|
||||
"session_id = \"demo\" # @param {type:\"string\"}\n",
|
||||
"query = \"What is the weather in SF?\" # @param {type:\"string\"}\n",
|
||||
"session_id = \"demo\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"test_agent(\n",
|
||||
" running_agent=agent,\n",
|
||||
@@ -882,7 +882,7 @@
|
||||
"\n",
|
||||
"# @markdown This section will deploy the agent on Vertex AI.\n",
|
||||
"# @markdown The supported regions for agent engine are listed [here](https://cloud.google.com/vertex-ai/generative-ai/docs/agent-engine/overview#supported-regions).\n",
|
||||
"region_to_deploy_agent = \"us-central1\" # @param {type:\"string\"}\n",
|
||||
"region_to_deploy_agent = \"us-central1\" # @param {type:\"string\"}\n",
|
||||
"vertexai.init(project=PROJECT_ID, location=region_to_deploy_agent, staging_bucket=BUCKET_URI)\n",
|
||||
"\n",
|
||||
"remote_agent = agent_engines.create(\n",
|
||||
@@ -919,8 +919,8 @@
|
||||
"\n",
|
||||
"remote_agent = agent_engines.get(remote_agent_resource_name)\n",
|
||||
"\n",
|
||||
"query = \"What is the weather in SF?\" # @param {type:\"string\"}\n",
|
||||
"session_id = \"demo\" # @param {type:\"string\"}\n",
|
||||
"query = \"What is the weather in SF?\" # @param {type:\"string\"}\n",
|
||||
"session_id = \"demo\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"test_agent(\n",
|
||||
" running_agent=remote_agent,\n",
|
||||
@@ -978,7 +978,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"name": "model_garden_integration_with_adk.ipynb",
|
||||
"name": "model_garden_integration_with_agent.ipynb",
|
||||
"toc_visible": true,
|
||||
"provenance": [],
|
||||
"collapsed_sections": [
|
||||
Reference in New Issue
Block a user