Add llama3.1 tool calling (#1148)

This commit is contained in:
Lance Martin
2024-07-26 08:08:22 -07:00
committed by GitHub
parent 585c5c41ce
commit 4b51c27461
2 changed files with 111 additions and 64 deletions
File diff suppressed because one or more lines are too long
@@ -15,6 +15,7 @@
"\n",
"```\n",
"ollama pull llama3-groq-tool-use\n",
"ollama pull llama3.1\n",
"```\n",
"\n",
"And also, we'll use the Ollama partner package.\n",
@@ -39,35 +40,39 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "120c1da8-e45e-4ffa-9ac1-a536026c7e1c",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.0\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.1.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install -qU langchain-ollama"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"id": "32c0504b-007a-4af6-9976-c7294ed26b73",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"USER_AGENT environment variable not set, consider setting it to identify your requests.\n"
]
}
],
"outputs": [],
"source": [
"# /// LLM ///\n",
"\n",
"from langchain_ollama import ChatOllama\n",
"\n",
"llm = ChatOllama(\n",
" model=\"llama3-groq-tool-use\",\n",
" # model=\"llama3-groq-tool-use\",\n",
" model=\"llama3.1\",\n",
" temperature=0,\n",
")\n",
"\n",
@@ -129,14 +134,13 @@
" for d in web_results\n",
" ]\n",
"\n",
"\n",
"# Tool list\n",
"tools = [retrieve_documents, web_search]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 9,
"id": "30052f47-2b5d-46f5-9873-eb716145cda1",
"metadata": {},
"outputs": [],
@@ -148,11 +152,9 @@
"from langgraph.graph.message import AnyMessage, add_messages\n",
"from typing_extensions import TypedDict\n",
"\n",
"\n",
"class State(TypedDict):\n",
" messages: Annotated[list[AnyMessage], add_messages]\n",
"\n",
"\n",
"class Assistant:\n",
" def __init__(self, runnable: Runnable):\n",
" \"\"\"\n",
@@ -209,7 +211,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 10,
"id": "40504a0b-8a99-4420-a6bf-561c62e893d1",
"metadata": {},
"outputs": [
@@ -282,7 +284,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 11,
"id": "43c633d5-e7a7-4b7c-8dc7-760a3b032e95",
"metadata": {},
"outputs": [],
@@ -301,9 +303,19 @@
"response = predict_react_agent_answer(example)"
]
},
{
"cell_type": "markdown",
"id": "bf82fa52-9e6c-4f37-94ae-91450dac602e",
"metadata": {},
"source": [
"See trace with llama3.1 here:\n",
"\n",
"https://smith.langchain.com/public/44d0c7dd-a756-47ad-8025-ee7ae6469ecb/r"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "cd74a0b3-be40-46cd-97bf-ef9676878289",
"metadata": {},
"outputs": [],
@@ -311,6 +323,24 @@
"example = {\"input\": \"Get me information about the current weather in SF.\"}\n",
"response = predict_react_agent_answer(example)"
]
},
{
"cell_type": "markdown",
"id": "8cac91bf-c975-44a2-a9fd-99706fee5735",
"metadata": {},
"source": [
"See trace with llama3.1 here:\n",
"\n",
"https://smith.langchain.com/public/7a4938e3-f94f-4e04-a162-bf592fba4643/r"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "74b813cb-18ed-42d8-b313-6ee56ded4bcc",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {