From 07f23c2d45643d6a87354fb5a275173a165d5d99 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Tue, 5 Mar 2024 08:58:06 -0800 Subject: [PATCH] docs: anthropic multimodal (#18586) --- docs/docs/integrations/chat/anthropic.ipynb | 88 ++++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/docs/docs/integrations/chat/anthropic.ipynb b/docs/docs/integrations/chat/anthropic.ipynb index 5229b902fc..0bc37365b8 100644 --- a/docs/docs/integrations/chat/anthropic.ipynb +++ b/docs/docs/integrations/chat/anthropic.ipynb @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "id": "8199ef8f-eb8b-4253-9ea0-6c24a013ca4c", "metadata": { "ExecuteTime": { @@ -93,7 +93,7 @@ "AIMessage(content='저는 파이썬을 사랑합니다.\\n\\nTranslation:\\nI love Python.')" ] }, - "execution_count": 3, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -206,11 +206,93 @@ " print(chunk.content, end=\"\", flush=True)" ] }, + { + "cell_type": "markdown", + "id": "70d5e0fb", + "metadata": {}, + "source": [ + "## Multimodal\n", + "\n", + "Anthropic's Claude-3 models are compatible with both image and text inputs. You can use this as follows:" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, + "id": "3e9d1ab5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# open ../../../static/img/brand/wordmark.png as base64 str\n", + "import base64\n", + "from pathlib import Path\n", + "\n", + "from IPython.display import HTML\n", + "\n", + "img_path = Path(\"../../../static/img/brand/wordmark.png\")\n", + "img_base64 = base64.b64encode(img_path.read_bytes()).decode(\"utf-8\")\n", + "\n", + "# display b64 image in notebook\n", + "HTML(f'')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, "id": "b6bb2aa2", "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "AIMessage(content='This logo is for LangChain, which appears to be some kind of software or technology platform based on the name and minimalist design style of the logo featuring a silhouette of a bird (likely an eagle or hawk) and the company name in a simple, modern font.')" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from langchain_core.messages import HumanMessage\n", + "\n", + "chat = ChatAnthropic(model=\"claude-3-opus-20240229\")\n", + "messages = [\n", + " HumanMessage(\n", + " content=[\n", + " {\n", + " \"type\": \"image_url\",\n", + " \"image_url\": {\n", + " # langchain logo\n", + " \"url\": f\"data:image/png;base64,{img_base64}\", # noqa: E501\n", + " },\n", + " },\n", + " {\"type\": \"text\", \"text\": \"What is this logo for?\"},\n", + " ]\n", + " )\n", + "]\n", + "chat.invoke(messages)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a381f8e", + "metadata": {}, "outputs": [], "source": [] }