docs: Tutorials up to date (#1734)

* edits

* add js code to web voyager
This commit is contained in:
Isaac Francisco
2024-09-17 08:11:41 -07:00
committed by GitHub
parent 0bf4bf8b6b
commit bfd18f76dd
23 changed files with 1398 additions and 587 deletions
@@ -254,7 +254,7 @@
"\n",
"retrieval_grader = grade_prompt | structured_llm_grader\n",
"question = \"agent memory\"\n",
"docs = retriever.get_relevant_documents(question)\n",
"docs = retriever.invoke(question)\n",
"doc_txt = docs[1].page_content\n",
"print(retrieval_grader.invoke({\"question\": question, \"document\": doc_txt}))"
]
@@ -110,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "af8379bd-7eae-4ba6-b632-12e89eab9920",
"metadata": {},
"outputs": [],
@@ -132,7 +132,16 @@
"execution_count": 3,
"id": "f9ff6b99-080d-4827-b2cb-f775543d76f5",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Downloading: 100%|██████████| 274M/274M [00:43<00:00, 6.38MiB/s] \n",
"Verifying: 100%|██████████| 274M/274M [00:00<00:00, 618MiB/s] \n"
]
}
],
"source": [
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
"from langchain_community.document_loaders import WebBaseLoader\n",
@@ -178,6 +187,14 @@
"id": "7045e064-e666-4aea-9111-6e9d2007f27e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/var/folders/td/vzm913rx77x21csd90g63_7c0000gn/T/ipykernel_7200/1754575056.py:22: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 1.0. Use invoke instead.\n",
" docs = retriever.get_relevant_documents(question)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
@@ -215,7 +232,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"id": "813cdcef-8b75-4214-a2ed-b89077b3d287",
"metadata": {},
"outputs": [
@@ -257,15 +274,25 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"id": "aeb8b373-0289-4dec-bd4b-8b2701200301",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/isaachershenson/.pyenv/versions/3.11.9/lib/python3.11/site-packages/langsmith/client.py:5301: LangChainBetaWarning: The function `loads` is in beta. It is actively being worked on, so the API may change.\n",
" prompt = loads(json.dumps(prompt_object.manifest))\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" In an LLM-powered autonomous agent system, the Large Language Model (LLM) functions as the agent's brain. The agent has key components including memory, planning, and reflection mechanisms. The memory component is a long-term memory module that records a comprehensive list of agents experience in natural language. It includes a memory stream, which is an external database for storing past experiences. The reflection mechanism synthesizes memories into higher-level inferences over time and guides the agent's future behavior.\n"
"1. In an LLM-powered autonomous agent system, the memory component is divided into short-term and long-term memories. Short-term memory utilizes in-context learning, while long-term memory provides the capability to retain and recall information over extended periods using an external vector store.\n",
"2. The long-term memory module, also known as the memory stream, records a comprehensive list of agents' experiences in natural language.\n",
"3. The agent learns to call external APIs for extra information that is missing from the model weights, including current information, code execution capability, access to proprietary information sources and more.\n"
]
}
],
@@ -299,7 +326,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"id": "38345cff-e2d0-436e-aa09-599522a61eed",
"metadata": {},
"outputs": [
@@ -309,7 +336,7 @@
"{'score': 'yes'}"
]
},
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -339,7 +366,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"id": "9771caa1-5542-47c3-8354-aeeafcf51964",
"metadata": {},
"outputs": [
@@ -349,7 +376,7 @@
"{'score': 'yes'}"
]
},
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -379,17 +406,17 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"id": "830ba5f7-9c8d-4c01-83b1-e4d51d40d48f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"' What is agent memory and how can it be effectively utilized in vector database retrieval?'"
"\" What is the function of an agent's memory in a given context?\""
]
},
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -422,7 +449,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"id": "6c3c1c70-ff84-41e8-bf72-738ed52f2dde",
"metadata": {},
"outputs": [],
@@ -448,7 +475,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"id": "6e09087e-b2a9-437a-abee-129e426df799",
"metadata": {},
"outputs": [],
@@ -475,7 +502,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 12,
"id": "7c5fa507-77ae-426a-a65f-f518b9525bd0",
"metadata": {},
"outputs": [],
@@ -700,7 +727,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 13,
"id": "450eb313-ca75-4a43-b57e-7034bd3f40bf",
"metadata": {},
"outputs": [],
@@ -752,7 +779,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 14,
"id": "b095c1db-8bd1-4a34-937c-1a9b74ae74ff",
"metadata": {},
"outputs": [
@@ -762,11 +789,35 @@
"text": [
"---ROUTE QUESTION---\n",
"What is the AlphaCodium paper about?\n",
"{'datasource': 'web_search'}\n",
"web_search\n",
"---ROUTE QUESTION TO WEB SEARCH---\n",
"---WEB SEARCH---\n",
"\"Node 'web_search':\"\n",
"{'datasource': 'vectorstore'}\n",
"vectorstore\n",
"---ROUTE QUESTION TO RAG---\n",
"---RETRIEVE---\n",
"\"Node 'retrieve':\"\n",
"'\\n---\\n'\n",
"---CHECK DOCUMENT RELEVANCE TO QUESTION---\n",
"---GRADE: DOCUMENT NOT RELEVANT---\n",
"---GRADE: DOCUMENT NOT RELEVANT---\n",
"---GRADE: DOCUMENT NOT RELEVANT---\n",
"---GRADE: DOCUMENT NOT RELEVANT---\n",
"---ASSESS GRADED DOCUMENTS---\n",
"---DECISION: ALL DOCUMENTS ARE NOT RELEVANT TO QUESTION, TRANSFORM QUERY---\n",
"\"Node 'grade_documents':\"\n",
"'\\n---\\n'\n",
"---TRANSFORM QUERY---\n",
"\"Node 'transform_query':\"\n",
"'\\n---\\n'\n",
"---RETRIEVE---\n",
"\"Node 'retrieve':\"\n",
"'\\n---\\n'\n",
"---CHECK DOCUMENT RELEVANCE TO QUESTION---\n",
"---GRADE: DOCUMENT NOT RELEVANT---\n",
"---GRADE: DOCUMENT RELEVANT---\n",
"---GRADE: DOCUMENT RELEVANT---\n",
"---GRADE: DOCUMENT NOT RELEVANT---\n",
"---ASSESS GRADED DOCUMENTS---\n",
"---DECISION: GENERATE---\n",
"\"Node 'grade_documents':\"\n",
"'\\n---\\n'\n",
"---GENERATE---\n",
"---CHECK HALLUCINATIONS---\n",
@@ -775,14 +826,15 @@
"---DECISION: GENERATION ADDRESSES QUESTION---\n",
"\"Node 'generate':\"\n",
"'\\n---\\n'\n",
"(' The AlphaCodium paper introduces a new approach for code generation by '\n",
" 'Large Language Models (LLMs). It presents AlphaCodium, an iterative process '\n",
" 'that involves generating additional data to aid the flow, and testing it on '\n",
" 'the CodeContests dataset. The results show that AlphaCodium outperforms '\n",
" \"DeepMind's AlphaCode and AlphaCode2 without fine-tuning a model. The \"\n",
" 'approach includes a pre-processing phase for problem reasoning in natural '\n",
" 'language and an iterative code generation phase with runs and fixes against '\n",
" 'tests.')\n"
"(' The \"AlphaCodium\" research paper appears to focus on the development and '\n",
" 'comparison of an autonomous agent system powered by a large language model '\n",
" '(LLM). The system is compared with several baselines, including ED, source '\n",
" 'policy, and RL^2. The LLM-powered agent demonstrates impressive performance '\n",
" 'in in-context reinforcement learning, getting close to the performance of '\n",
" 'RL^2 despite only using offline RL and learning much faster than other '\n",
" 'baselines. Additionally, the paper discusses the use of adversarial attacks '\n",
" 'on LLMs as a potential threat to their safe behavior in real-world '\n",
" 'applications.')\n"
]
}
],
@@ -830,7 +882,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.9"
}
},
"nbformat": 4,
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -188,7 +188,7 @@
"\n",
"retrieval_grader = grade_prompt | structured_llm_grader\n",
"question = \"agent memory\"\n",
"docs = retriever.get_relevant_documents(question)\n",
"docs = retriever.invoke(question)\n",
"doc_txt = docs[1].page_content\n",
"print(retrieval_grader.invoke({\"question\": question, \"document\": doc_txt}))"
]
File diff suppressed because one or more lines are too long
@@ -109,7 +109,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 3,
"id": "565a6d44-2c9f-4fff-b1ec-eea05df9350d",
"metadata": {},
"outputs": [],
@@ -152,23 +152,15 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"id": "1fafad21-60cc-483e-92a3-6a7edb1838e3",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/rlm/miniforge3/envs/llama2/lib/python3.11/site-packages/langchain_core/_api/deprecation.py:119: LangChainDeprecationWarning: The method `BaseRetriever.get_relevant_documents` was deprecated in langchain-core 0.1.46 and will be removed in 0.3.0. Use invoke instead.\n",
" warn_deprecated(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"binary_score='yes'\n"
"binary_score='no'\n"
]
}
],
@@ -209,14 +201,14 @@
"\n",
"retrieval_grader = grade_prompt | structured_llm_grader\n",
"question = \"agent memory\"\n",
"docs = retriever.get_relevant_documents(question)\n",
"docs = retriever.invoke(question)\n",
"doc_txt = docs[1].page_content\n",
"print(retrieval_grader.invoke({\"question\": question, \"document\": doc_txt}))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"id": "dcd77cc1-4587-40ec-b633-5364eab9e1ec",
"metadata": {},
"outputs": [
@@ -224,7 +216,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The design of generative agents combines LLM with memory, planning, and reflection mechanisms to enable agents to behave conditioned on past experience and interact with other agents. Long-term memory provides the agent with the capability to retain and recall infinite information over extended periods. Short-term memory is utilized for in-context learning.\n"
"The design of generative agents combines LLM with memory, planning, and reflection mechanisms to enable agents to behave conditioned on past experience. Memory stream is a long-term memory module that records a comprehensive list of agents' experience in natural language. LLM functions as the agent's brain in an autonomous agent system.\n"
]
}
],
@@ -256,7 +248,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"id": "e78931ec-940c-46ad-a0b2-f43f953f1fd7",
"metadata": {},
"outputs": [
@@ -266,7 +258,7 @@
"GradeHallucinations(binary_score='yes')"
]
},
"execution_count": 4,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
@@ -304,7 +296,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 9,
"id": "bd62276f-bf26-40d0-8cff-e07b10e00321",
"metadata": {},
"outputs": [
@@ -314,7 +306,7 @@
"GradeAnswer(binary_score='yes')"
]
},
"execution_count": 5,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -352,7 +344,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 10,
"id": "c6f4c70e-1660-4149-82c0-837f19fc9fb5",
"metadata": {},
"outputs": [
@@ -362,7 +354,7 @@
"\"What is the role of memory in an agent's functioning?\""
]
},
"execution_count": 6,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
@@ -223,7 +223,7 @@
"\n",
"retrieval_grader = prompt | llm | JsonOutputParser()\n",
"question = \"agent memory\"\n",
"docs = retriever.get_relevant_documents(question)\n",
"docs = retriever.invoke(question)\n",
"doc_txt = docs[1].page_content\n",
"print(retrieval_grader.invoke({\"question\": question, \"document\": doc_txt}))"
]