docs:Updated integration docs structure for chat/google_vertex_ai_palm (#16201)

Description: 

- checked that the doc chat/google_vertex_ai_palm is using new
functions: invoke, stream etc.
- added Gemini example
- fixed wrong output in Sanskrit example

Issue: https://github.com/langchain-ai/langchain/issues/15664
Dependencies: None
Twitter handle: None
pull/16529/head
Anastasiia Manokhina 8 months ago committed by GitHub
parent fdbfa6b2c8
commit ce595f0203
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,6 +18,14 @@
"\n", "\n",
"Note: This is separate from the Google PaLM integration. Google has chosen to offer an enterprise version of PaLM through GCP, and this supports the models made available through there. \n", "Note: This is separate from the Google PaLM integration. Google has chosen to offer an enterprise version of PaLM through GCP, and this supports the models made available through there. \n",
"\n", "\n",
"ChatVertexAI exposes all foundational models available in Google Cloud:\n",
"\n",
"- Gemini (`gemini-pro` and `gemini-pro-vision`)\n",
"- PaLM 2 for Text (`text-bison`)\n",
"- Codey for Code Generation (`codechat-bison`)\n",
"\n",
"For a full and updated list of available models visit [VertexAI documentation](https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/overview).\n",
"\n",
"By default, Google Cloud [does not use](https://cloud.google.com/vertex-ai/docs/generative-ai/data-governance#foundation_model_development) customer data to train its foundation models as part of Google Cloud`s AI/ML Privacy Commitment. More details about how Google processes data can also be found in [Google's Customer Data Processing Addendum (CDPA)](https://cloud.google.com/terms/data-processing-addendum).\n", "By default, Google Cloud [does not use](https://cloud.google.com/vertex-ai/docs/generative-ai/data-governance#foundation_model_development) customer data to train its foundation models as part of Google Cloud`s AI/ML Privacy Commitment. More details about how Google processes data can also be found in [Google's Customer Data Processing Addendum (CDPA)](https://cloud.google.com/terms/data-processing-addendum).\n",
"\n", "\n",
"To use `Google Cloud Vertex AI` PaLM you must have the `langchain-google-vertexai` Python package installed and either:\n", "To use `Google Cloud Vertex AI` PaLM you must have the `langchain-google-vertexai` Python package installed and either:\n",
@ -35,9 +43,7 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"tags": []
},
"outputs": [], "outputs": [],
"source": [ "source": [
"%pip install --upgrade --quiet langchain-google-vertexai" "%pip install --upgrade --quiet langchain-google-vertexai"
@ -45,7 +51,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -64,7 +70,7 @@
"AIMessage(content=\" J'aime la programmation.\")" "AIMessage(content=\" J'aime la programmation.\")"
] ]
}, },
"execution_count": 8, "execution_count": null,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -98,7 +104,7 @@
"AIMessage(content=\"J'aime la programmation.\")" "AIMessage(content=\"J'aime la programmation.\")"
] ]
}, },
"execution_count": 9, "execution_count": null,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -123,7 +129,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -132,7 +138,7 @@
"AIMessage(content=' プログラミングが大好きです')" "AIMessage(content=' プログラミングが大好きです')"
] ]
}, },
"execution_count": 4, "execution_count": null,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -159,28 +165,17 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"execution": {
"iopub.execute_input": "2023-06-17T21:09:25.423568Z",
"iopub.status.busy": "2023-06-17T21:09:25.423213Z",
"iopub.status.idle": "2023-06-17T21:09:25.429641Z",
"shell.execute_reply": "2023-06-17T21:09:25.429060Z",
"shell.execute_reply.started": "2023-06-17T21:09:25.423546Z"
},
"tags": []
},
"source": [ "source": [
"## Code generation chat models\n", "## Code generation chat models\n",
"You can now leverage the Codey API for code chat within Vertex AI. The model name is:\n", "You can now leverage the Codey API for code chat within Vertex AI. The model available is:\n",
"- codechat-bison: for code assistance" "- `codechat-bison`: for code assistance"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": { "metadata": {},
"tags": []
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
@ -242,7 +237,7 @@
" model_name=\"codechat-bison\", max_output_tokens=1000, temperature=0.5\n", " model_name=\"codechat-bison\", max_output_tokens=1000, temperature=0.5\n",
")\n", ")\n",
"\n", "\n",
"message = chat.invoke(\"Write a Python function to identify all prime numbers\")\n", "message = chat.invoke(\"Write a Python function generating all prime numbers\")\n",
"print(message.content)" "print(message.content)"
] ]
}, },
@ -266,7 +261,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -320,7 +315,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -353,7 +348,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -362,7 +357,7 @@
"MyModel(name='Erick', age=27)" "MyModel(name='Erick', age=27)"
] ]
}, },
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -389,7 +384,7 @@
"source": [ "source": [
"## Asynchronous calls\n", "## Asynchronous calls\n",
"\n", "\n",
"We can make asynchronous calls via the Runnables [Async Interface](/docs/expression_language/interface)" "We can make asynchronous calls via the Runnables [Async Interface](/docs/expression_language/interface)."
] ]
}, },
{ {
@ -414,10 +409,10 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"AIMessage(content=' Why do you love programming?')" "AIMessage(content=' अहं प्रोग्रामनं प्रेमामि')"
] ]
}, },
"execution_count": 6, "execution_count": null,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -428,6 +423,10 @@
")\n", ")\n",
"human = \"{text}\"\n", "human = \"{text}\"\n",
"prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", human)])\n", "prompt = ChatPromptTemplate.from_messages([(\"system\", system), (\"human\", human)])\n",
"\n",
"chat = ChatVertexAI(\n",
" model_name=\"chat-bison\", max_output_tokens=1000, temperature=0.5\n",
")\n",
"chain = prompt | chat\n", "chain = prompt | chat\n",
"\n", "\n",
"asyncio.run(\n", "asyncio.run(\n",
@ -483,43 +482,15 @@
" sys.stdout.write(chunk.content)\n", " sys.stdout.write(chunk.content)\n",
" sys.stdout.flush()" " sys.stdout.flush()"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
"environment": {
"kernel": "python3",
"name": "common-cpu.m108",
"type": "gcloud",
"uri": "gcr.io/deeplearning-platform-release/base-cpu:m108"
},
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "",
"language": "python", "name": ""
"name": "python3"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "name": "python"
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
},
"vscode": {
"interpreter": {
"hash": "cc99336516f23363341912c6723b01ace86f02e26b4290be1efc0677e2e2ec24"
}
} }
}, },
"nbformat": 4, "nbformat": 4,

Loading…
Cancel
Save