added history and support for system_message as param (#14824)

- **Description:** added support for chat_history for Google
GenerativeAI (to actually use the `chat` API) plus since Gemini
currently doesn't have a support for SystemMessage, added support for it
only if a user provides additional `convert_system_message_to_human`
flag during model initialization (in this case, SystemMessage would be
prepanded to the first HumanMessage)
  - **Issue:** #14710 
  - **Dependencies:** any dependencies required for this change,
- **Tag maintainer:** for a quicker response, tag the relevant
maintainer (see below),
  - **Twitter handle:** lkuligin

---------

Co-authored-by: William FH <13333726+hinthornw@users.noreply.github.com>
This commit is contained in:
Leonid Kuligin
2023-12-19 03:23:14 +01:00
committed by GitHub
parent 2861766d0d
commit 2d0f1cae8c
4 changed files with 166 additions and 64 deletions

View File

@@ -136,6 +136,32 @@
"print(result.content)"
]
},
{
"cell_type": "markdown",
"id": "9e55d043-bb2f-44e3-9134-c39a1abe3a9e",
"metadata": {},
"source": [
"Gemini doesn't support `SystemMessage` at the moment, but it can be added to the first human message in the row. If you want such behavior, just set the `convert_system_message_to_human` to True:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a64b523-9710-4d15-9944-1e3cc567a52b",
"metadata": {},
"outputs": [],
"source": [
"from langchain.schema.messages import HumanMessage, SystemMessage\n",
"\n",
"model = ChatGoogleGenerativeAI(model=\"gemini-pro\", convert_system_message_to_human=True)\n",
"model(\n",
" [\n",
" SystemMessage(content=\"Answer only yes or no.\"),\n",
" HumanMessage(content=\"Is apple a fruit?\"),\n",
" ]\n",
")"
]
},
{
"cell_type": "markdown",
"id": "40773fac-b24d-476d-91c8-2da8fed99b53",