mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-17 21:25:46 +02:00
Finalize
This commit is contained in:
@@ -165,7 +165,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 2,
|
||||
"id": "bYK-e0diGdPf",
|
||||
"metadata": {
|
||||
"colab": {
|
||||
@@ -179,8 +179,8 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[{'id': '3370f44e-01e3-4dc5-a439-543235380ec4', 'function': {'name': 'web_search', 'arguments': '{\"query\": \"who will the bears pick in the NFL draft\"}'}, 'type': 'function'}]\n",
|
||||
"[{'id': '08933491-a419-4b65-8a48-3ff1e55d8eba', 'function': {'name': 'vectorstore', 'arguments': '{\"query\": \"types of agent memory\"}'}, 'type': 'function'}]\n",
|
||||
"[{'id': 'f811e3b9-052e-49db-a234-5fc3efbcc5ba', 'function': {'name': 'web_search', 'arguments': '{\"query\": \"NFL draft bears first pick\"}'}, 'type': 'function'}]\n",
|
||||
"[{'id': '4bc53113-8f32-4d6d-ac9b-c07ef9aae9fd', 'function': {'name': 'vectorstore', 'arguments': '{\"query\": \"types of agent memory\"}'}, 'type': 'function'}]\n",
|
||||
"False\n"
|
||||
]
|
||||
}
|
||||
@@ -243,14 +243,6 @@
|
||||
"outputId": "57a5c27b-044b-4df5-f55d-7bf23d3976d1"
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"/Users/rlm/miniforge3/envs/llama2/lib/python3.11/site-packages/langchain_core/_api/beta_decorator.py:87: LangChainBetaWarning: The function `with_structured_output` is in beta. It is actively being worked on, so the API may change.\n",
|
||||
" warn_beta(\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
@@ -317,7 +309,7 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"There are three types of agent memory: sensory, short-term and long-term. Sensory memory lasts for a few seconds and deals with sensory information. Short-term memory is finite and restricted by the length of an agent's context window. Long-term memory is infinite and can last for extended periods.\n"
|
||||
"There are three types of agent memory: sensory memory, short-term memory, and long-term memory.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -354,19 +346,9 @@
|
||||
"print(generation)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "Ezioqk0tGZ-J",
|
||||
"metadata": {
|
||||
"id": "Ezioqk0tGZ-J"
|
||||
},
|
||||
"source": [
|
||||
"Hallucination Grader"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"execution_count": 6,
|
||||
"id": "bc000a7d-84b6-4eb2-88ad-65cc62a44431",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
@@ -374,7 +356,7 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Hello! I'm doing well, thank you for asking. As an AI chatbot, I respond to questions and requests while adhering to ethical guidelines and remain polite and helpful. How can I assist you today?\n"
|
||||
"I don't have feelings as an AI chatbot, but I'm here to assist you with any queries or concerns you may have. How can I help you today?\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -413,7 +395,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 7,
|
||||
"id": "y0msuR2DHQkY",
|
||||
"metadata": {
|
||||
"colab": {
|
||||
@@ -429,7 +411,7 @@
|
||||
"GradeHallucinations(binary_score='yes')"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -465,7 +447,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"execution_count": 8,
|
||||
"id": "f0c08d14-77a0-4eed-b882-2d636abb22a3",
|
||||
"metadata": {
|
||||
"colab": {
|
||||
@@ -481,7 +463,7 @@
|
||||
"GradeAnswer(binary_score='yes')"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -592,7 +574,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"execution_count": 11,
|
||||
"id": "b76b5ec3-0720-443d-85b1-c0e79659ca0a",
|
||||
"metadata": {
|
||||
"id": "b76b5ec3-0720-443d-85b1-c0e79659ca0a"
|
||||
@@ -681,26 +663,6 @@
|
||||
" continue\n",
|
||||
" return {\"documents\": filtered_docs, \"question\": question}\n",
|
||||
"\n",
|
||||
"def transform_query(state):\n",
|
||||
" \"\"\"\n",
|
||||
" Transform the query to produce a better question.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" state (dict): The current graph state\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" state (dict): Updates question key with a re-phrased question\n",
|
||||
" \"\"\"\n",
|
||||
"\n",
|
||||
" print(\"---TRANSFORM QUERY---\")\n",
|
||||
" question = state[\"question\"]\n",
|
||||
" documents = state[\"documents\"]\n",
|
||||
"\n",
|
||||
" # Re-write question\n",
|
||||
" print(\"WARNING: about to rewrite question but this shouldn't happen...\")\n",
|
||||
" better_question = question_rewriter.invoke({\"question\": question})\n",
|
||||
" return {\"documents\": documents, \"question\": better_question}\n",
|
||||
"\n",
|
||||
"def web_search(state):\n",
|
||||
" \"\"\"\n",
|
||||
" Web search based on the re-phrased question.\n",
|
||||
@@ -832,7 +794,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"execution_count": 12,
|
||||
"id": "67854e07-9293-4c3c-bf9a-bc9a605570ee",
|
||||
"metadata": {
|
||||
"id": "67854e07-9293-4c3c-bf9a-bc9a605570ee"
|
||||
@@ -888,7 +850,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"execution_count": 13,
|
||||
"id": "29acc541-d726-4b75-84d1-a215845fe88a",
|
||||
"metadata": {
|
||||
"colab": {
|
||||
@@ -908,18 +870,13 @@
|
||||
"\"Node 'web_search':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"---GENERATE---\n",
|
||||
"\"Node 'generate':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"---CHECK HALLUCINATIONS---\n",
|
||||
"---DECISION: GENERATION IS GROUNDED IN DOCUMENTS---\n",
|
||||
"---GRADE GENERATION vs QUESTION---\n",
|
||||
"---DECISION: GENERATION ADDRESSES QUESTION---\n",
|
||||
"\"Node '__end__':\"\n",
|
||||
"\"Node 'generate':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"('Several sources expect the Chicago Bears to select USC quarterback Caleb '\n",
|
||||
" 'Williams with their first pick in the 2024 NFL Draft. The Bears have two '\n",
|
||||
" 'top-10 selections and the first overall pick is expected to be used on '\n",
|
||||
" 'Williams.')\n"
|
||||
"'The Bears are expected to draft Caleb Williams with their first pick.'\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -946,12 +903,12 @@
|
||||
"source": [
|
||||
"Trace:\n",
|
||||
"\n",
|
||||
"https://smith.langchain.com/public/09066150-24ec-4174-8551-7b31749899c4/r"
|
||||
"https://smith.langchain.com/public/623da7bb-84a7-4e53-a63e-7ccd77fb9be5/r"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 31,
|
||||
"execution_count": 14,
|
||||
"id": "69a985dd-03c6-45af-a67b-b15746a2cb5f",
|
||||
"metadata": {
|
||||
"colab": {
|
||||
@@ -975,24 +932,18 @@
|
||||
"---GRADE: DOCUMENT RELEVANT---\n",
|
||||
"---GRADE: DOCUMENT RELEVANT---\n",
|
||||
"---GRADE: DOCUMENT RELEVANT---\n",
|
||||
"\"Node 'grade_documents':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"---ASSESS GRADED DOCUMENTS---\n",
|
||||
"---DECISION: GENERATE---\n",
|
||||
"---GENERATE---\n",
|
||||
"\"Node 'generate':\"\n",
|
||||
"\"Node 'grade_documents':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"---GENERATE---\n",
|
||||
"---CHECK HALLUCINATIONS---\n",
|
||||
"---DECISION: GENERATION IS GROUNDED IN DOCUMENTS---\n",
|
||||
"---GRADE GENERATION vs QUESTION---\n",
|
||||
"---DECISION: GENERATION ADDRESSES QUESTION---\n",
|
||||
"\"Node '__end__':\"\n",
|
||||
"\"Node 'generate':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"('There are three types of agent memory: sensory, short-term, and long-term. '\n",
|
||||
" 'Sensory memory lasts for a few seconds and includes visual, auditory and '\n",
|
||||
" 'touch impressions. Short-term memory lasts between 20 to 30 seconds and '\n",
|
||||
" 'stores currently known information. Long-term memory can last up to decades '\n",
|
||||
" 'and has an infinite capacity.')\n"
|
||||
"'Sensory, short-term, and long-term memory.'\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -1020,12 +971,12 @@
|
||||
"source": [
|
||||
"Trace:\n",
|
||||
"\n",
|
||||
"https://smith.langchain.com/public/b630aca8-3417-4b0c-95d9-80a24c592c13/r"
|
||||
"https://smith.langchain.com/public/57f3973b-6879-4fbe-ae31-9ae524c3a697/r"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 32,
|
||||
"execution_count": 15,
|
||||
"id": "qPwP_2PNiOjQ",
|
||||
"metadata": {
|
||||
"id": "qPwP_2PNiOjQ"
|
||||
@@ -1040,11 +991,8 @@
|
||||
"---LLM Fallback---\n",
|
||||
"\"Node 'llm_fallback':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"\"Node '__end__':\"\n",
|
||||
"'\\n---\\n'\n",
|
||||
"(\"Hello! I'm doing well, thank you for asking. As an AI chatbot, I experience \"\n",
|
||||
" 'no highs or lows and am always ready to assist you to the best of my '\n",
|
||||
" 'abilities!')\n"
|
||||
"(\"I don't have feelings as an AI assistant, but I'm here to help you with your \"\n",
|
||||
" 'queries. How can I assist you today?')\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -1063,10 +1011,20 @@
|
||||
"pprint.pprint(value [\"generation\"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4107c8a4-6171-4c1b-840a-77a3d09f84fc",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Trace: \n",
|
||||
"\n",
|
||||
"https://smith.langchain.com/public/1f628ee4-8d2d-451e-aeb1-5d5e0ede2b4f/r"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "dfaa345d-a829-4601-bb9a-392f06364f49",
|
||||
"id": "ce3cda0a-c4bd-41ea-830b-d992f27fde15",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
|
||||
Reference in New Issue
Block a user