docs, google-vertex[patch]: function docs (#16231)

This commit is contained in:
Erick Friis 2024-01-18 13:15:09 -08:00 committed by GitHub
parent f2b2d59e82
commit aa35b43bcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 15 deletions

View File

@ -34,28 +34,18 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"^C\n",
"\u001b[31mERROR: Operation cancelled by user\u001b[0m\u001b[31m\n",
"\u001b[0mNote: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [ "source": [
"%pip install --upgrade --quiet langchain-google-vertexai" "%pip install --upgrade --quiet langchain-google-vertexai"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -352,6 +342,47 @@
"pprint(result.generations[0][0].generation_info)" "pprint(result.generations[0][0].generation_info)"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Function Calling with Gemini\n",
"\n",
"We can call Gemini models with tools."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"MyModel(name='Erick', age=27)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain.pydantic_v1 import BaseModel\n",
"from langchain_google_vertexai import create_structured_runnable\n",
"\n",
"llm = ChatVertexAI(model_name=\"gemini-pro\")\n",
"\n",
"\n",
"class MyModel(BaseModel):\n",
" name: str\n",
" age: int\n",
"\n",
"\n",
"chain = create_structured_runnable(MyModel, llm)\n",
"chain.invoke(\"My name is Erick and I'm 27 years old\")"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
@ -386,7 +417,7 @@
"AIMessage(content=' Why do you love programming?')" "AIMessage(content=' Why do you love programming?')"
] ]
}, },
"execution_count": 7, "execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }

View File

@ -24,7 +24,7 @@ def _format_pydantic_to_vertex_function(
return { return {
"name": schema["title"], "name": schema["title"],
"description": schema["description"], "description": schema.get("description", ""),
"parameters": { "parameters": {
"properties": { "properties": {
k: { k: {